verify-cached-files.js 929 B

12345678910111213141516171819
  1. 'use strict'
  2. const cacache = require('cacache')
  3. const log = require('npmlog')
  4. module.exports = verifyCachedFiles
  5. function verifyCachedFiles (cache, cb) {
  6. log.info('verifyCachedFiles', `Verifying cache at ${cache}`)
  7. cacache.verify(cache).then((stats) => {
  8. log.info('verifyCachedFiles', `Verification complete. Stats: ${JSON.stringify(stats, 2)}`)
  9. if (stats.reclaimedCount || stats.badContentCount || stats.missingContent) {
  10. stats.badContentCount && log.warn('verifyCachedFiles', `Corrupted content removed: ${stats.badContentCount}`)
  11. stats.reclaimedCount && log.warn('verifyCachedFiles', `Content garbage-collected: ${stats.reclaimedCount} (${stats.reclaimedSize} bytes)`)
  12. stats.missingContent && log.warn('verifyCachedFiles', `Missing content: ${stats.missingContent}`)
  13. log.warn('verifyCachedFiles', 'Cache issues have been fixed')
  14. }
  15. return stats
  16. }).then((s) => cb(null, s), cb)
  17. }