Skip to content

Commit

Permalink
Follow linked folders (#36)
Browse files Browse the repository at this point in the history
* Update archiver dependency

* Support compressing symlinks on Windows

- Add test cases for file and directory symlinks
- Add support for compressing file and symlinks on Windows
- Test on Windows 10 node 12.16.1
- Test on Ubuntu 18.04 node 12.16.1 both with and without native zip
available in path.

* Fix EMFILE error, too many open readStream issue.
  • Loading branch information
dworthen committed Jul 27, 2020
1 parent bac4990 commit 3fb9e44
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 106 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
node_modules/
.idea
tmp/
test/fixtures/subdir-symlink
test/fixtures/file-symlink.txt
test/validArchive.zip
test/validARchiveExtract
.DS_Store
21 changes: 20 additions & 1 deletion lib/bestzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ const nodeZip = options =>
}
}

function walkDir(fullPath) {
const files = fs.readdirSync(fullPath).map(f => {
const filePath = path.join(fullPath, f);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
return walkDir(filePath);
}
return filePath;
});
return files.reduce((acc, cur) => acc.concat(cur), []);
}

function addSource(source, next) {
const fullPath = path.resolve(cwd, source);
const destPath = source;
Expand All @@ -90,7 +102,14 @@ const nodeZip = options =>
return next(err);
}
if (stats.isDirectory()) {
archive.directory(fullPath, destPath);
// Walk directory. Works on directories and directory symlinks.
const files = walkDir(fullPath);
files.forEach(f => {
const subPath = f.substring(fullPath.length);
archive.file(f, {
name: destPath + subPath
});
});
} else if (stats.isFile()) {
archive.file(fullPath, { stats: stats, name: destPath });
}
Expand Down

0 comments on commit 3fb9e44

Please sign in to comment.