Skip to content

Cannot overwrite existing directory if symlink present (CentOS 7) #138

Open
@troy-rudolph

Description

@troy-rudolph

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 #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions