Skip to content

Commit

Permalink
fix: don't clobber time when verifying cache (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed May 2, 2023
1 parent e227c50 commit 62b2d8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/entry-index.js
Expand Up @@ -109,12 +109,12 @@ async function compact (cache, key, matchFn, opts = {}) {
module.exports.insert = insert

async function insert (cache, key, integrity, opts = {}) {
const { metadata, size } = opts
const { metadata, size, time } = opts
const bucket = bucketPath(cache, key)
const entry = {
key,
integrity: integrity && ssri.stringify(integrity),
time: Date.now(),
time: time || Date.now(),
size,
metadata,
}
Expand Down
1 change: 1 addition & 0 deletions lib/verify.js
Expand Up @@ -224,6 +224,7 @@ async function rebuildBucket (cache, bucket, stats, opts) {
await index.insert(cache, entry.key, entry.integrity, {
metadata: entry.metadata,
size: entry.size,
time: entry.time,
})
stats.totalEntries++
} catch (err) {
Expand Down
10 changes: 10 additions & 0 deletions test/verify.js
Expand Up @@ -400,3 +400,13 @@ t.test('handles multiple hashes of the same content', async t => {
t.match(ls.test.integrity, 'sha512')
t.match(ls.test.integrity, 'sha256')
})

t.test('does not clobber entry time', async t => {
const cache = t.testdir()
const content = Buffer.from('CONTENT!', 'utf8')
await cacache.put(cache, 'test', content)
const entryBefore = await cacache.get.info(cache, 'test')
await cacache.verify(cache)
const entryAfter = await cacache.get.info(cache, 'test')
t.equal(entryBefore.time, entryAfter.time, 'time does not change')
})

0 comments on commit 62b2d8d

Please sign in to comment.