kevva / decompress

Extracting archives made easy
MIT License
415 stars 51 forks source link

ENOENT while extracting an tar with hardlinks #93

Open xingrz opened 2 years ago

xingrz commented 2 years ago

File: gcc-arm-none-eabi-9-2020-q2-update-mac.tar.bz2 from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads/9-2020-q2-update

[Error: ENOENT: no such file or directory, link './arm-none-eabi/lib/libg.a' -> '/Users/XiNGRZ/****/arm-none-eabi/lib/libc.a'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'link',
  path: './arm-none-eabi/lib/libg.a',
  dest: '/Users/XiNGRZ/****/arm-none-eabi/lib/libc.a'
}

Just did some investigation and found:

https://github.com/kevva/decompress/blob/84a8c1046946add1a6ae01c54dbebf312e4ffc85/index.js#L121

I think x.linkname should be joined with the output path. Otherwise fsPromises.symlink can't find the target.

xingrz commented 2 years ago

Finally I've fixed the problem. I would like to share my solution.

The issue was brought by hard links:

  1. The source of hard link should be an absolute path, instead of a relative path
  2. Creation of hard links should be deferred until all files are wrote to the file system

I've make a test case to reproduce the issue, as well as the solution. Since my fork was refactored far ahead from this project, I'm not going to make a PR.

ilg-ul commented 1 year ago

I also encountered this error.

Is it possible to fix this package to include the patch suggested by @xingrz ?