Skip to content

Commit

Permalink
fix: unpacking tarballs that contain hard links (#7062)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Sep 6, 2023
1 parent d194bae commit b394718
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/modern-wombats-tease.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 2 additions & 0 deletions store/cafs/src/parseTarball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
Binary file not shown.
9 changes: 9 additions & 0 deletions store/cafs/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit b394718

Please sign in to comment.