Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unpacking tarballs that contain hard links #7062

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zkochan , If the file type is a hard link, there is a string field at offset 157 with length 100 that contains the file to be linked to. Pretty sure the file contents aren't stored twice in the archive. https://www.subspacefield.org/~vax/tar_format.html

// 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)
})