diff --git a/lib/content/path.js b/lib/content/path.js index 7bb25e63..eb45eb60 100644 --- a/lib/content/path.js +++ b/lib/content/path.js @@ -1,11 +1,21 @@ 'use strict' +var contentVer = require('../../package.json')['cache-version'].content var path = require('path') +// Current format of content file path: +// +// ~/.my-cache/content-v1/sha512/ba/bada55deadbeefc0ffee +// module.exports = contentPath function contentPath (cache, address, hashAlgorithm) { address = address && address.toLowerCase() hashAlgorithm = hashAlgorithm ? hashAlgorithm.toLowerCase() : 'sha512' return path.join( - cache, 'content', hashAlgorithm, address.slice(0, 2), address) + cache, + `content-v${contentVer}`, + hashAlgorithm, + address.slice(0, 2), + address + ) } diff --git a/lib/entry-index.js b/lib/entry-index.js index b752cd4a..961abcfb 100644 --- a/lib/entry-index.js +++ b/lib/entry-index.js @@ -12,6 +12,8 @@ const Promise = require('bluebird') const split = require('split') const through = require('mississippi').through +const indexV = require('../package.json')['cache-version'].index + module.exports.insert = insert function insert (cache, key, digest, opts) { opts = opts || {} @@ -105,7 +107,7 @@ function del (cache, key) { module.exports.lsStream = lsStream function lsStream (cache) { - const indexDir = path.join(cache, 'index') + const indexDir = bucketDir(cache) const stream = through.obj() fs.readdir(indexDir, function (err, buckets) { if (err && err.code === 'ENOENT') { @@ -177,10 +179,14 @@ function notFoundError (cache, key) { return err } +function bucketDir (cache) { + return path.join(cache, `index-v${indexV}`) +} + module.exports._bucketPath = bucketPath function bucketPath (cache, key) { const hashed = hashKey(key) - return path.join(cache, 'index', hashed.slice(0, 2), hashed) + return path.join(bucketDir(cache), hashed.slice(0, 2), hashed) } module.exports._hashKey = hashKey diff --git a/package.json b/package.json index 74f65e5f..72cd2c66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,10 @@ { "name": "cacache", "version": "5.0.3", + "cache-version": { + "content": "1", + "index": "1" + }, "description": "General content-addressable cache system that maintains a filesystem registry of file data.", "main": "index.js", "files": [