Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: npm/cacache
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v16.1.1
Choose a base ref
...
head repository: npm/cacache
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v16.1.2
Choose a head ref
  • 2 commits
  • 20 files changed
  • 2 contributors

Commits on Aug 15, 2022

  1. fix: linting (#121)

    wraithgar authored Aug 15, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wmouchere William Mouchère
    Copy the full SHA
    a683cff View commit details
  2. chore(main): release 16.1.2 (#122)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored Aug 15, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wmouchere William Mouchère
    Copy the full SHA
    befff62 View commit details
Showing with 1,058 additions and 1,404 deletions.
  1. +7 −0 CHANGELOG.md
  2. +1 −1 lib/content/read.js
  3. +2 −0 lib/content/write.js
  4. +1 −0 lib/entry-index.js
  5. +1 −0 lib/get.js
  6. +1 −1 package.json
  7. +65 −103 test/content/read.js
  8. +14 −19 test/content/write.chownr.js
  9. +86 −119 test/content/write.js
  10. +69 −70 test/entry-index.find.js
  11. +156 −202 test/entry-index.insert.js
  12. +11 −18 test/entry-index.js
  13. +215 −279 test/get.js
  14. +20 −28 test/ls.js
  15. +65 −88 test/put.js
  16. +25 −52 test/rm.js
  17. +11 −30 test/util/fix-owner.js
  18. +15 −25 test/util/move-file.js
  19. +35 −47 test/util/tmp.js
  20. +258 −322 test/verify.js
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [16.1.2](https://github.com/npm/cacache/compare/v16.1.1...v16.1.2) (2022-08-15)


### Bug Fixes

* linting ([#121](https://github.com/npm/cacache/issues/121)) ([a683cff](https://github.com/npm/cacache/commit/a683cffdfd956e1a4ac0e5ccbfa30615192e1ea0))

## [16.1.1](https://github.com/npm/cacache/compare/v16.1.0...v16.1.1) (2022-06-02)


2 changes: 1 addition & 1 deletion lib/content/read.js
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ function readStream (cache, integrity, opts = {}) {
return stream.emit('error', sizeError(size, stat.size))
}

readPipeline(cpath, stat.size, sri, stream)
return readPipeline(cpath, stat.size, sri, stream)
}).catch(err => stream.emit('error', err))

return stream
2 changes: 2 additions & 0 deletions lib/content/write.js
Original file line number Diff line number Diff line change
@@ -80,9 +80,11 @@ class CacacheWriteStream extends Flush {
// defer this one tick by rejecting a promise on it.
return Promise.reject(e).catch(cb)
}
// eslint-disable-next-line promise/catch-or-return
this.handleContentP.then(
(res) => {
res.integrity && this.emit('integrity', res.integrity)
// eslint-disable-next-line promise/always-return
res.size !== null && this.emit('size', res.size)
cb()
},
1 change: 1 addition & 0 deletions lib/entry-index.js
Original file line number Diff line number Diff line change
@@ -285,6 +285,7 @@ function lsStream (cache) {
}))
}))
stream.end()
return stream
}).catch(err => stream.emit('error', err))

return stream
1 change: 1 addition & 0 deletions lib/get.js
Original file line number Diff line number Diff line change
@@ -155,6 +155,7 @@ function getStream (cache, key, opts = {}) {
stream.unshift(memoStream)
}
stream.unshift(src)
return stream
}).catch((err) => stream.emit('error', err))

return stream
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cacache",
"version": "16.1.1",
"version": "16.1.2",
"cache-version": {
"content": "2",
"index": "5"
168 changes: 65 additions & 103 deletions test/content/read.js
Original file line number Diff line number Diff line change
@@ -28,17 +28,16 @@ const getReadStatFailure = (t, err) => getRead(t, {
}),
})

t.test('read: returns a Promise with cache content data', function (t) {
t.test('read: returns a Promise with cache content data', async t => {
const CONTENT = Buffer.from('foobarbaz')
const INTEGRITY = ssri.fromData(CONTENT)
const CACHE = t.testdir(
CacheContent({
[INTEGRITY]: CONTENT,
})
)
return read(CACHE, INTEGRITY).then((data) => {
t.same(data, CONTENT, 'cache contents read correctly')
})
const data = await read(CACHE, INTEGRITY)
t.same(data, CONTENT, 'cache contents read correctly')
})

t.test('read.sync: reads synchronously', (t) => {
@@ -54,7 +53,7 @@ t.test('read.sync: reads synchronously', (t) => {
t.end()
})

t.test('read.stream: returns a stream with cache content data', function (t) {
t.test('read.stream: returns a stream with cache content data', async t => {
const CONTENT = Buffer.from('foobarbaz')
const INTEGRITY = ssri.fromData(CONTENT)
const CACHE = t.testdir(
@@ -63,16 +62,15 @@ t.test('read.stream: returns a stream with cache content data', function (t) {
})
)
const stream = read.stream(CACHE, INTEGRITY)
return Promise.all([
const [fromStream, fromBulk] = await Promise.all([
stream.concat(),
read(CACHE, INTEGRITY, { size: CONTENT.length }),
]).then(([fromStream, fromBulk]) => {
t.same(fromStream, CONTENT, 'stream data checks out')
t.same(fromBulk, CONTENT, 'promise data checks out')
})
])
t.same(fromStream, CONTENT, 'stream data checks out')
t.same(fromBulk, CONTENT, 'promise data checks out')
})

t.test('read: allows hashAlgorithm configuration', function (t) {
t.test('read: allows hashAlgorithm configuration', async t => {
const CONTENT = Buffer.from('foobarbaz')
const HASH = 'sha384'
const INTEGRITY = ssri.fromData(CONTENT, { algorithms: [HASH] })
@@ -82,16 +80,15 @@ t.test('read: allows hashAlgorithm configuration', function (t) {
})
)
const stream = read.stream(CACHE, INTEGRITY)
return Promise.all([
const [fromStream, fromBulk] = await Promise.all([
stream.concat(),
read(CACHE, INTEGRITY),
]).then(([fromStream, fromBulk]) => {
t.same(fromStream, CONTENT, 'stream used algorithm')
t.same(fromBulk, CONTENT, 'promise used algorithm')
})
])
t.same(fromStream, CONTENT, 'stream used algorithm')
t.same(fromBulk, CONTENT, 'promise used algorithm')
})

t.test('read: errors if content missing', function (t) {
t.test('read: errors if content missing', async t => {
const CACHE = t.testdir({})
const stream = read.stream(CACHE, 'sha512-whatnot')
stream.on('data', function (data) {
@@ -100,28 +97,19 @@ t.test('read: errors if content missing', function (t) {
stream.on('end', function () {
throw new Error('end was emitted even though stream errored')
})
return Promise.all([
stream.promise().catch((err) => {
if (err.code === 'ENOENT') {
return err
}

throw err
}),
read(CACHE, 'sha512-whatnot').catch((err) => {
if (err.code === 'ENOENT') {
return err
}

throw err
}),
]).then(([streamErr, bulkErr]) => {
t.match(streamErr, { code: 'ENOENT' }, 'stream got the right error')
t.match(bulkErr, { code: 'ENOENT' }, 'bulk got the right error')
})
await t.rejects(
stream.promise(),
{ code: 'ENOENT' },
'stream got the right error'
)
await t.rejects(
read(CACHE, 'sha512-whatnot'),
{ code: 'ENOENT' },
'bulk got the right error'
)
})

t.test('read: errors if content fails checksum', function (t) {
t.test('read: errors if content fails checksum', async t => {
const CONTENT = Buffer.from('foobarbaz')
const INTEGRITY = ssri.fromData(CONTENT)
const CACHE = t.testdir(
@@ -133,28 +121,19 @@ t.test('read: errors if content fails checksum', function (t) {
stream.on('end', function () {
throw new Error('end was emitted even though stream errored')
})
return Promise.all([
stream.promise().catch((err) => {
if (err.code === 'EINTEGRITY') {
return err
}

throw err
}),
read(CACHE, INTEGRITY).catch((err) => {
if (err.code === 'EINTEGRITY') {
return err
}

throw err
}),
]).then(([streamErr, bulkErr]) => {
t.match(streamErr, { code: 'EINTEGRITY' }, 'stream got the right error')
t.match(bulkErr, { code: 'EINTEGRITY' }, 'bulk got the right error')
})
await t.rejects(
stream.promise(),
{ code: 'EINTEGRITY' },
'stream got the right error'
)
await t.rejects(
read(CACHE, INTEGRITY),
{ code: 'EINTEGRITY' },
'bulk got the right error'
)
})

t.test('read: errors if content size does not match size option', function (t) {
t.test('read: errors if content size does not match size option', async t => {
const CONTENT = Buffer.from('foobarbaz')
const INTEGRITY = ssri.fromData(CONTENT)
const CACHE = t.testdir(
@@ -166,27 +145,16 @@ t.test('read: errors if content size does not match size option', function (t) {
stream.on('end', function () {
throw new Error('end was called even though stream errored')
})
return Promise.all([
stream.promise().catch((err) => {
if (err.code === 'EBADSIZE') {
return err
}

throw err
}),
read(CACHE, INTEGRITY, {
size: CONTENT.length,
}).catch((err) => {
if (err.code === 'EBADSIZE') {
return err
}

throw err
}),
]).then(([streamErr, bulkErr]) => {
t.match(streamErr, { code: 'EBADSIZE' }, 'stream got the right error')
t.match(bulkErr, { code: 'EBADSIZE' }, 'bulk got the right error')
})
await t.rejects(
stream.promise(),
{ code: 'EBADSIZE' },
'stream got the right error'
)
await t.rejects(
read(CACHE, INTEGRITY, { size: CONTENT.length }),
{ code: 'EBADSIZE' },
'bulk got the right error'
)
})

t.test('read: error while parsing provided integrity data', function (t) {
@@ -344,27 +312,26 @@ t.test('read.sync: content size value does not match option', (t) => {
t.end()
})

t.test('hasContent: tests content existence', (t) => {
t.test('hasContent: tests content existence', async t => {
const CACHE = t.testdir(
CacheContent({
'sha1-deadbeef': '',
})
)
return Promise.all([
read.hasContent(CACHE, 'sha1-deadbeef').then((content) => {
t.ok(content.sri, 'returned sri for this content')
t.equal(content.size, 0, 'returned the right size for this content')
t.ok(content.stat.isFile(), 'returned actual stat object')
}),
read.hasContent(CACHE, 'sha1-not-there').then((content) => {
t.equal(content, false, 'returned false for missing content')
}),
read
.hasContent(CACHE, 'sha1-not-here sha1-also-not-here')
.then((content) => {
t.equal(content, false, 'multi-content hash failures work ok')
}),
])
const content = await read.hasContent(CACHE, 'sha1-deadbeef')
t.ok(content.sri, 'returned sri for this content')
t.equal(content.size, 0, 'returned the right size for this content')
t.ok(content.stat.isFile(), 'returned actual stat object')
await t.resolveMatch(
read.hasContent(CACHE, 'sha1-not-there'),
false,
'returned false for missing content'
)
await t.resolveMatch(
read.hasContent(CACHE, 'sha1-not-here sha1-also-not-here'),
false,
'multi-content hash failures work ok'
)
})

t.test('hasContent: permission error', (t) => {
@@ -457,7 +424,7 @@ t.test('hasContent.sync: no integrity provided', (t) => {
t.end()
})

t.test('copy: copies content to a destination path', (t) => {
t.test('copy: copies content to a destination path', async t => {
const CONTENT = Buffer.from('foobarbaz')
const INTEGRITY = ssri.fromData(CONTENT)
const CACHE = t.testdir(
@@ -466,14 +433,9 @@ t.test('copy: copies content to a destination path', (t) => {
})
)
const DEST = path.join(CACHE, 'foobar-file')
return read
.copy(CACHE, INTEGRITY, DEST)
.then(() => {
return fs.readFile(DEST)
})
.then((data) => {
t.same(data, CONTENT, 'file successfully copied')
})
await read.copy(CACHE, INTEGRITY, DEST)
const data = await fs.readFile(DEST)
t.same(data, CONTENT, 'file successfully copied')
})

t.test('copy.sync: copies content to a destination path synchronously', (t) => {
33 changes: 14 additions & 19 deletions test/content/write.chownr.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ const t = require('tap')

const contentPath = require('../../lib/content/path')

t.test('infers ownership from cache folder owner', (t) => {
t.test('infers ownership from cache folder owner', async t => {
const CACHE = t.testdir({ cache: {} })
const CONTENT = 'foobarbaz'
const INTEGRITY = ssri.fromData(CONTENT)
@@ -32,21 +32,16 @@ t.test('infers ownership from cache folder owner', (t) => {
},
})
t.plan(7)
return write.stream(CACHE, { hashAlgorithm: 'sha1' })
.end(CONTENT)
.promise()
.then(() => {
const cpath = contentPath(CACHE, INTEGRITY)
const expectedPaths = [
path.join(CACHE, path.relative(CACHE, cpath).split(path.sep)[0]),
cpath,
path.join(CACHE, 'tmp'),
]
t.same(
updatedPaths.sort(),
expectedPaths,
'all paths that needed user stuff set got set'
)
})
}
)
await write.stream(CACHE, { hashAlgorithm: 'sha1' }).end(CONTENT).promise()
const cpath = contentPath(CACHE, INTEGRITY)
const expectedPaths = [
path.join(CACHE, path.relative(CACHE, cpath).split(path.sep)[0]),
cpath,
path.join(CACHE, 'tmp'),
]
t.same(
updatedPaths.sort(),
expectedPaths,
'all paths that needed user stuff set got set'
)
})
Loading