max-mapper / max-mapper/extract-zip
Cannot overwrite existing directory if symlink present (CentOS 7)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 398
- Forks
- 144
- PR merge metrics
- No merged PRs in 30d
Description
Using extract-zip 2.0.1., node 16.19, and CentOS 7, there is an error when extracting a zip file using the "overwrite: true" option.
[Error: EEXIST: file already exists, symlink 'catalog_libraries.json' -> '/home/trudolph/exp/output/catalog/catalog_builds.json'] {
errno: -17,
code: 'EEXIST',
syscall: 'symlink',
path: 'catalog_libraries.json',
dest: '/home/trudolph/exp/output/catalog/catalog_builds.json'
}
It seems to me that it should overwrite the symlinks as well as the regular files.
Using information found in the source code and in https://github.com/maxogden/extract-zip/issues/20, I coded the following to make it work.
await extract('catalog2.zip', {
dir: realDest,
overwrite: true,
onEntry: (entry, zip) => {
// handle link overwrite
const mode = (entry.externalFileAttributes >> 16) & 0xFFFF; // convert to fs stat mode
const IFMT = 61440;
const IFLNK = 40960;
const symlink = (mode & IFMT) === IFLNK;
if (sysmlink) {
fs.unlinkSync(dir + '/' + entry.fileName);
}
console.log(entry);
}
});
This works adequately for now, but I am hoping that there will be a fix in extract-zip.
Thank you
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the extract entry point with overwrite: true and the onEntry callback described in the issue, then reproduce the EEXIST failure when an archive symlink targets an existing path. Trace the overwrite handling for regular files versus symlinks and verify that extraction replaces an existing symlink without requiring the callback workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100