fix: unpacking tarballs that contain hard links (#7062)

This commit is contained in:
Zoltan Kochan
2023-09-06 21:48:06 +03:00
committed by GitHub
parent d194baeb50
commit b3947185c6
4 changed files with 17 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/store.cafs": patch
"pnpm": patch
---
Tarballs that have hard links are now unpacked successfully. This fixes a regression introduced in v8.7.0, which was shipped with our new in-house tarball parser [#7062](https://github.com/pnpm/pnpm/pull/7062).

View File

@@ -12,6 +12,7 @@ export interface IFile {
}
const ZERO: number = '0'.charCodeAt(0)
const FILE_TYPE_HARD_LINK: number = '1'.charCodeAt(0)
const FILE_TYPE_SYMLINK: number = '2'.charCodeAt(0)
const FILE_TYPE_DIRECTORY: number = '5'.charCodeAt(0)
const SPACE: number = ' '.charCodeAt(0)
@@ -135,6 +136,7 @@ export function parseTarball (buffer: Buffer): IParseResult {
switch (fileType) {
case 0:
case ZERO:
case FILE_TYPE_HARD_LINK:
// The file mode is an octal number encoded as UTF-8. It is terminated by a NUL or space. Maximum length 8 characters.
mode = parseOctal(blockStart + MODE_OFFSET, 8)

View File

Binary file not shown.

View File

@@ -113,3 +113,12 @@ test('unpack an older version of tar that prefixes with spaces', () => {
'package.json',
])
})
test('unpack a tarball that contains hard links', () => {
const dest = tempy.directory()
const cafs = createCafs(dest)
const { filesIndex } = cafs.addFilesFromTarball(
fs.readFileSync(path.join(__dirname, 'fixtures/vue.examples.todomvc.todo-store-0.0.1.tgz'))
)
expect(Object.keys(filesIndex).length).toBeGreaterThan(0)
})