Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't clobber time when verifying cache #199

Merged
merged 1 commit into from May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
})