fix: don't unpack file duplicates

This commit is contained in:
Zoltan Kochan
2020-10-25 21:38:12 +02:00
parent bd833cc572
commit b3059f4f85
4 changed files with 24 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/cafs": patch
---
Don't unpack file duplicates to the content-addressable store.

View File

@@ -14,9 +14,9 @@ export default async function (
const extract = tar.extract()
const filesIndex = {}
await new Promise((resolve, reject) => {
extract.on('entry', async (header, fileStream, next) => {
const filename = header.name.substr(header.name.indexOf('/') + 1)
if (header.type !== 'file' || ignore(filename)) {
extract.on('entry', (header, fileStream, next) => {
const filename = header.name.substr(header.name.indexOf('/') + 1).replace(/\/\//g, '/')
if (header.type !== 'file' || ignore(filename) || filesIndex[filename]) {
fileStream.resume()
next()
return

View File

Binary file not shown.

View File

@@ -52,3 +52,19 @@ describe('checkFilesIntegrity()', () => {
})).toBeFalsy()
})
})
test('file names are normalized when unpacking a tarball', async () => {
const dest = tempy.directory()
console.log(dest)
const cafs = createCafs(dest)
const filesIndex = await cafs.addFilesFromTarball(
fs.createReadStream(path.join(__dirname, 'fixtures/colorize-semver-diff.tgz'))
)
expect(Object.keys(filesIndex).sort()).toStrictEqual([
'LICENSE',
'README.md',
'lib/index.d.ts',
'lib/index.js',
'package.json',
])
})