Skip to content

Commit

Permalink
Do not pass mode for directories to YAZL.
Browse files Browse the repository at this point in the history
This allows directories to be crated with their default platform-appropriate mode (0775).
  • Loading branch information
Jimbly committed Jun 27, 2020
1 parent e04a1f8 commit 50215c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ module.exports = (filename, options) => {
if (file.isNull() && file.stat && file.stat.isDirectory && file.stat.isDirectory()) {
zip.addEmptyDirectory(pathname, {
mtime: options.modifiedTime || file.stat.mtime || new Date(),
// Set executable bit on directories if any other bits are set for that user/group/all
// Fixes creating unusable zip files on platforms that do not use an executable bit
mode: file.stat.mode | (((file.stat.mode >> 1) | (file.stat.mode >> 2)) & 0o111)
// Do *not* pass a mode for a directory, creates platform-dependent zip
// files (zip files created on Windows that cannot be opened on MacOS).
// Re-enable if this PR is resolved: https://github.com/thejoshwolfe/yazl/pull/59
// mode: file.stat.mode
});
} else {
const stat = {
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test.cb('should not skip empty directories', t => {
isDirectory() {
return true;
},
mode: 0o644
mode: 0o664
};

unzipper.on('data', file => {
Expand All @@ -106,7 +106,7 @@ test.cb('should not skip empty directories', t => {

unzipper.on('end', () => {
t.is(files[0].path, 'foo');
t.is(files[0].stat.mode, 0o755);
t.is(files[0].stat.mode, 0o775);
t.end();
});

Expand Down

0 comments on commit 50215c7

Please sign in to comment.