Skip to content

Commit

Permalink
fix: pass expected integrity to cacache
Browse files Browse the repository at this point in the history
this allows cacache to clean up after an integrity error instead of abandoning the temp files like it does today
  • Loading branch information
nlf committed May 18, 2022
1 parent ec2db21 commit a88213e
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions lib/cache/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class CacheEntry {
algorithms: this.options.algorithms,
metadata: getMetadata(this.request, this.response, this.options),
size,
integrity: this.options.integrity,
}

let body = null
Expand All @@ -273,11 +274,9 @@ class CacheEntry {
},
}))

let abortStream
const onResume = () => {
const tee = new Minipass()
const cacheStream = cacache.put.stream(this.options.cachePath, this.key, cacheOpts)
abortStream = cacheStream
tee.pipe(cacheStream)
// TODO if the cache write fails, log a warning but return the response anyway
cacheStream.promise().then(cacheWriteResolve, cacheWriteReject)
Expand All @@ -287,11 +286,6 @@ class CacheEntry {

body.once('resume', onResume)
body.once('end', () => body.removeListener('resume', onResume))
this.response.body.on('error', (err) => {
// listen for errors from the actual response and avoid writing data that we
// know to be invalid to the cache
abortStream.destroy(err)
})
} else {
await cacache.index.insert(this.options.cachePath, this.key, null, cacheOpts)
}
Expand Down

0 comments on commit a88213e

Please sign in to comment.