Skip to content

Commit

Permalink
Fix creating unusable zip files on Windows (missing executable bit on…
Browse files Browse the repository at this point in the history
… directories)
  • Loading branch information
Jimbly committed May 8, 2020
1 parent c77d53c commit 5fc7532
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ 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(),
mode: file.stat.mode
// 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 | (file.stat.mode>>1) | (file.stat.mode>>2)) & parseInt('0111', 8)
});
} else {
const stat = {
Expand Down
4 changes: 3 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ test.cb('should not skip empty directories', t => {
const stats = {
isDirectory() {
return true;
}
},
mode: 0o644,
};

unzipper.on('data', file => {
Expand All @@ -105,6 +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.end();
});

Expand Down

0 comments on commit 5fc7532

Please sign in to comment.