Skip to content

Conversation

epeicher
Copy link

@epeicher epeicher commented May 23, 2025

This change will expose an option when creating an Archiver object to allow following the symlinks, so instead of archiving the symlinks, the target folders and files of the symlinks will be archived.

The usage will be something like:

const archive = new ZipArchive( {
  followSymLinks: true,
  zlib: { level: 9 },
} );

Proposed changes

  • Add an option to the CoreOptions object named followSymlinks
  • Use that option to populate the follow option of the readdirGlob function, so the symlinks are followed.

Testing instructions

  • Clone this repository and apply this branch
  • Create a new Javascript repository and install this repo, for example:
    • Create a new folder in the same root folder where the node-archiver repo was cloned, e.g. /test-archiver`
    • cd into that folder
    • Run npm init -y
    • Run npm i ../node-archiver
    • Create another folder in another location that you will use for testing to compress the files, e.g. /tmp/test-folder
    • Include some symbolic links in that folder that point to directories and to individual files
    • So you should have a similar structure than the following:
      CleanShot 2025-05-26 at 13 03 36@2x
  • cd into the test-archiver folder
  • Create the following code to test the new option in a file named index.js:
import { ZipArchive } from "archiver";
import fs from "fs";

const archive = new ZipArchive({
  followSymLinks: true,
  zlib: { level: 9 },
});

const output = fs.createWriteStream("example.zip");

archive.on("warning", function (err) {
  if (err.code === "ENOENT") {
    // log warning
    console.log(err);
  } else {
    // throw error
    throw err;
  }
});

output.on("close", function () {
  console.log(archive.pointer() + " total bytes");
  console.log("archiver has been finalized and the output file descriptor has closed.");
});

archive.on("error", function (err) {
  throw err;
});

archive.pipe(output);

archive.directory("../test-folder", "example");

archive.finalize().catch(console.error).then(() => console.log('Done'));
  • Run the above code with node index.js
  • Check there are not unexpected errors
  • Check that a new example.zip file has been created in that folder
  • unzip the file and confirm the symlinks created have been followed, so you should see standard folders and files

@epeicher epeicher changed the title {WIP} - Add an option to allow to follow the symlinks [WIP] - Add an option to allow to follow the symlinks May 23, 2025
@epeicher epeicher marked this pull request as ready for review May 26, 2025 11:28
@epeicher epeicher changed the title [WIP] - Add an option to allow to follow the symlinks Add an option to allow to follow the symlinks May 26, 2025
@epeicher epeicher changed the title Add an option to allow to follow the symlinks Add an option to allow following the symlinks May 26, 2025
@sejas
Copy link

sejas commented May 28, 2025

@ctalkington, do you think we could consider exposing this follow symlinks readdir-glob option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants