Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2018-04-12 23:46:12 +0300
committerRebecca Turner <me@re-becca.org>2018-04-12 23:46:13 +0300
commit0573d91e57c068635a3ad4187b9792afd7b5e22f (patch)
tree6ed4095080a0197f3bbdcd41fa7b56049bd1fbb6 /node_modules/cacache/lib/verify.js
parent3c0bbcb8e5440a3b90fabcce85d7a1d31e2ecbe7 (diff)
cacache@11.0.1
PR-URL: https://github.com/zkat/cacache/pull/128 Credit: @zkat
Diffstat (limited to 'node_modules/cacache/lib/verify.js')
-rw-r--r--node_modules/cacache/lib/verify.js37
1 files changed, 25 insertions, 12 deletions
diff --git a/node_modules/cacache/lib/verify.js b/node_modules/cacache/lib/verify.js
index 6a01004c9..80d59bdc5 100644
--- a/node_modules/cacache/lib/verify.js
+++ b/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)
})
}
@@ -195,13 +208,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())))
}