summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/cacache/lib
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/cacache/lib')
-rw-r--r--deps/npm/node_modules/cacache/lib/content/read.js43
-rw-r--r--deps/npm/node_modules/cacache/lib/content/write.js4
-rw-r--r--deps/npm/node_modules/cacache/lib/entry-index.js27
-rw-r--r--deps/npm/node_modules/cacache/lib/util/tmp.js12
-rw-r--r--deps/npm/node_modules/cacache/lib/verify.js40
5 files changed, 87 insertions, 39 deletions
diff --git a/deps/npm/node_modules/cacache/lib/content/read.js b/deps/npm/node_modules/cacache/lib/content/read.js
index b09ad5cb40..5c1a6f2f29 100644
--- a/deps/npm/node_modules/cacache/lib/content/read.js
+++ b/deps/npm/node_modules/cacache/lib/content/read.js
@@ -3,6 +3,7 @@
const BB = require('bluebird')
const contentPath = require('./path')
+const figgyPudding = require('figgy-pudding')
const fs = require('graceful-fs')
const PassThrough = require('stream').PassThrough
const pipe = BB.promisify(require('mississippi').pipe)
@@ -11,9 +12,13 @@ const Y = require('../util/y.js')
BB.promisifyAll(fs)
+const ReadOpts = figgyPudding({
+ size: {}
+})
+
module.exports = read
function read (cache, integrity, opts) {
- opts = opts || {}
+ opts = ReadOpts(opts)
return pickContentSri(cache, integrity).then(content => {
const sri = content.sri
const cpath = contentPath(cache, sri)
@@ -32,7 +37,7 @@ function read (cache, integrity, opts) {
module.exports.stream = readStream
module.exports.readStream = readStream
function readStream (cache, integrity, opts) {
- opts = opts || {}
+ opts = ReadOpts(opts)
const stream = new PassThrough()
pickContentSri(
cache, integrity
@@ -56,7 +61,7 @@ if (fs.copyFile) {
module.exports.copy = copy
}
function copy (cache, integrity, dest, opts) {
- opts = opts || {}
+ opts = ReadOpts(opts)
return pickContentSri(cache, integrity).then(content => {
const sri = content.sri
const cpath = contentPath(cache, sri)
@@ -68,17 +73,17 @@ module.exports.hasContent = hasContent
function hasContent (cache, integrity) {
if (!integrity) { return BB.resolve(false) }
return pickContentSri(cache, integrity)
- .catch({code: 'ENOENT'}, () => false)
- .catch({code: 'EPERM'}, err => {
- if (process.platform !== 'win32') {
- throw err
- } else {
- return false
- }
- }).then(content => {
- if (!content.sri) return false
- return ({ sri: content.sri, size: content.stat.size })
- })
+ .catch({code: 'ENOENT'}, () => false)
+ .catch({code: 'EPERM'}, err => {
+ if (process.platform !== 'win32') {
+ throw err
+ } else {
+ return false
+ }
+ }).then(content => {
+ if (!content.sri) return false
+ return ({ sri: content.sri, size: content.stat.size })
+ })
}
module.exports._pickContentSri = pickContentSri
@@ -95,6 +100,16 @@ function pickContentSri (cache, integrity) {
return BB.any(sri[sri.pickAlgorithm()].map(meta => {
return pickContentSri(cache, meta)
}))
+ .catch(err => {
+ if ([].some.call(err, e => e.code === 'ENOENT')) {
+ throw Object.assign(
+ new Error('No matching content found for ' + sri.toString()),
+ {code: 'ENOENT'}
+ )
+ } else {
+ throw err[0]
+ }
+ })
}
}
diff --git a/deps/npm/node_modules/cacache/lib/content/write.js b/deps/npm/node_modules/cacache/lib/content/write.js
index a79ae92902..c71363413c 100644
--- a/deps/npm/node_modules/cacache/lib/content/write.js
+++ b/deps/npm/node_modules/cacache/lib/content/write.js
@@ -28,7 +28,9 @@ function write (cache, data, opts) {
if (typeof opts.size === 'number' && data.length !== opts.size) {
return BB.reject(sizeError(opts.size, data.length))
}
- const sri = ssri.fromData(data, opts)
+ const sri = ssri.fromData(data, {
+ algorithms: opts.algorithms
+ })
if (opts.integrity && !ssri.checkData(data, opts.integrity, opts)) {
return BB.reject(checksumError(opts.integrity, sri))
}
diff --git a/deps/npm/node_modules/cacache/lib/entry-index.js b/deps/npm/node_modules/cacache/lib/entry-index.js
index face0fe79c..43fa7b95b1 100644
--- a/deps/npm/node_modules/cacache/lib/entry-index.js
+++ b/deps/npm/node_modules/cacache/lib/entry-index.js
@@ -4,6 +4,7 @@ const BB = require('bluebird')
const contentPath = require('./content/path')
const crypto = require('crypto')
+const figgyPudding = require('figgy-pudding')
const fixOwner = require('./util/fix-owner')
const fs = require('graceful-fs')
const hashToSegments = require('./util/hash-to-segments')
@@ -29,9 +30,16 @@ module.exports.NotFoundError = class NotFoundError extends Error {
}
}
+const IndexOpts = figgyPudding({
+ metadata: {},
+ size: {},
+ uid: {},
+ gid: {}
+})
+
module.exports.insert = insert
function insert (cache, key, integrity, opts) {
- opts = opts || {}
+ opts = IndexOpts(opts)
const bucket = bucketPath(cache, key)
const entry = {
key,
@@ -116,9 +124,10 @@ function lsStream (cache) {
}, new Map())
return getKeyToEntry.then(reduced => {
- return Array.from(reduced.values()).map(
- entry => stream.push(formatEntry(cache, entry))
- )
+ for (let entry of reduced.values()) {
+ const formatted = formatEntry(cache, entry)
+ formatted && stream.push(formatted)
+ }
}).catch({code: 'ENOENT'}, nop)
})
})
@@ -196,9 +205,9 @@ function hashEntry (str) {
function hash (str, digest) {
return crypto
- .createHash(digest)
- .update(str)
- .digest('hex')
+ .createHash(digest)
+ .update(str)
+ .digest('hex')
}
function formatEntry (cache, entry) {
@@ -216,8 +225,8 @@ function formatEntry (cache, entry) {
function readdirOrEmpty (dir) {
return readdirAsync(dir)
- .catch({code: 'ENOENT'}, () => [])
- .catch({code: 'ENOTDIR'}, () => [])
+ .catch({code: 'ENOENT'}, () => [])
+ .catch({code: 'ENOTDIR'}, () => [])
}
function nop () {
diff --git a/deps/npm/node_modules/cacache/lib/util/tmp.js b/deps/npm/node_modules/cacache/lib/util/tmp.js
index 4fc4512cc8..65fc4b297e 100644
--- a/deps/npm/node_modules/cacache/lib/util/tmp.js
+++ b/deps/npm/node_modules/cacache/lib/util/tmp.js
@@ -2,14 +2,21 @@
const BB = require('bluebird')
+const figgyPudding = require('figgy-pudding')
const fixOwner = require('./fix-owner')
const path = require('path')
const rimraf = BB.promisify(require('rimraf'))
const uniqueFilename = require('unique-filename')
+const TmpOpts = figgyPudding({
+ tmpPrefix: {},
+ uid: {},
+ gid: {}
+})
+
module.exports.mkdir = mktmpdir
function mktmpdir (cache, opts) {
- opts = opts || {}
+ opts = TmpOpts(opts)
const tmpTarget = uniqueFilename(path.join(cache, 'tmp'), opts.tmpPrefix)
return fixOwner.mkdirfix(tmpTarget, opts.uid, opts.gid).then(() => {
return tmpTarget
@@ -22,11 +29,12 @@ function withTmp (cache, opts, cb) {
cb = opts
opts = null
}
- opts = opts || {}
+ opts = TmpOpts(opts)
return BB.using(mktmpdir(cache, opts).disposer(rimraf), cb)
}
module.exports.fix = fixtmpdir
function fixtmpdir (cache, opts) {
+ opts = TmpOpts(opts)
return fixOwner(path.join(cache, 'tmp'), opts.uid, opts.gid)
}
diff --git a/deps/npm/node_modules/cacache/lib/verify.js b/deps/npm/node_modules/cacache/lib/verify.js
index 6a01004c97..3468bc6b8e 100644
--- a/deps/npm/node_modules/cacache/lib/verify.js
+++ b/deps/npm/node_modules/cacache/lib/verify.js
@@ -3,6 +3,7 @@
const BB = require('bluebird')
const contentPath = require('./content/path')
+const figgyPudding = require('figgy-pudding')
const finished = BB.promisify(require('mississippi').finished)
const fixOwner = require('./util/fix-owner')
const fs = require('graceful-fs')
@@ -14,10 +15,22 @@ const ssri = require('ssri')
BB.promisifyAll(fs)
+const VerifyOpts = figgyPudding({
+ concurrency: {
+ default: 20
+ },
+ filter: {},
+ log: {
+ default: { silly () {} }
+ },
+ uid: {},
+ gid: {}
+})
+
module.exports = verify
function verify (cache, opts) {
- opts = opts || {}
- opts.log && opts.log.silly('verify', 'verifying cache at', cache)
+ opts = VerifyOpts(opts)
+ opts.log.silly('verify', 'verifying cache at', cache)
return BB.reduce([
markStartTime,
fixPerms,
@@ -40,7 +53,7 @@ function verify (cache, opts) {
})
}, {}).tap(stats => {
stats.runTime.total = stats.endTime - stats.startTime
- opts.log && opts.log.silly('verify', 'verification finished for', cache, 'in', `${stats.runTime.total}ms`)
+ opts.log.silly('verify', 'verification finished for', cache, 'in', `${stats.runTime.total}ms`)
})
}
@@ -53,7 +66,7 @@ function markEndTime (cache, opts) {
}
function fixPerms (cache, opts) {
- opts.log && opts.log.silly('verify', 'fixing cache permissions')
+ opts.log.silly('verify', 'fixing cache permissions')
return fixOwner.mkdirfix(cache, opts.uid, opts.gid).then(() => {
// TODO - fix file permissions too
return fixOwner.chownr(cache, opts.uid, opts.gid)
@@ -70,11 +83,11 @@ function fixPerms (cache, opts) {
// 5. If content is not marked as live, rimraf it.
//
function garbageCollect (cache, opts) {
- opts.log && opts.log.silly('verify', 'garbage collecting content')
+ opts.log.silly('verify', 'garbage collecting content')
const indexStream = index.lsStream(cache)
const liveContent = new Set()
indexStream.on('data', entry => {
- if (opts && opts.filter && !opts.filter(entry)) { return }
+ if (opts.filter && !opts.filter(entry)) { return }
liveContent.add(entry.integrity.toString())
})
return finished(indexStream).then(() => {
@@ -117,7 +130,7 @@ function garbageCollect (cache, opts) {
})
})
}
- }, {concurrency: opts.concurrency || 20}))
+ }, {concurrency: opts.concurrency}))
})
})
}
@@ -141,7 +154,7 @@ function verifyContent (filepath, sri) {
}
function rebuildIndex (cache, opts) {
- opts.log && opts.log.silly('verify', 'rebuilding index')
+ opts.log.silly('verify', 'rebuilding index')
return index.ls(cache).then(entries => {
const stats = {
missingContent: 0,
@@ -153,7 +166,7 @@ function rebuildIndex (cache, opts) {
if (entries.hasOwnProperty(k)) {
const hashed = index._hashKey(k)
const entry = entries[k]
- const excluded = opts && opts.filter && !opts.filter(entry)
+ const excluded = opts.filter && !opts.filter(entry)
excluded && stats.rejectedEntries++
if (buckets[hashed] && !excluded) {
buckets[hashed].push(entry)
@@ -170,7 +183,7 @@ function rebuildIndex (cache, opts) {
}
return BB.map(Object.keys(buckets), key => {
return rebuildBucket(cache, buckets[key], stats, opts)
- }, {concurrency: opts.concurrency || 20}).then(() => stats)
+ }, {concurrency: opts.concurrency}).then(() => stats)
})
}
@@ -184,7 +197,8 @@ function rebuildBucket (cache, bucket, stats, opts) {
return index.insert(cache, entry.key, entry.integrity, {
uid: opts.uid,
gid: opts.gid,
- metadata: entry.metadata
+ metadata: entry.metadata,
+ size: entry.size
}).then(() => { stats.totalEntries++ })
}).catch({code: 'ENOENT'}, () => {
stats.rejectedEntries++
@@ -195,13 +209,13 @@ function rebuildBucket (cache, bucket, stats, opts) {
}
function cleanTmp (cache, opts) {
- opts.log && opts.log.silly('verify', 'cleaning tmp directory')
+ opts.log.silly('verify', 'cleaning tmp directory')
return rimraf(path.join(cache, 'tmp'))
}
function writeVerifile (cache, opts) {
const verifile = path.join(cache, '_lastverified')
- opts.log && opts.log.silly('verify', 'writing verifile to ' + verifile)
+ opts.log.silly('verify', 'writing verifile to ' + verifile)
return fs.writeFileAsync(verifile, '' + (+(new Date())))
}