Skip to content

Commit 29340ba

Browse files
committed
fix: Set correct unix file type in external attributes
1 parent 42fe210 commit 29340ba

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

lib/archivers/zip/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = {
5252
EXT_FILE_ATTR_FILE: 020151000040, // 644 -rw-r--r-- = (((S_IFREG | 0644) << 16) | S_DOS_A) >>> 0
5353

5454
// Unix file types
55+
S_IFMT: 0170000, /* type of file mask */
5556
S_IFIFO: 010000, // named pipe (fifo)
5657
S_IFCHR: 020000, // character special
5758
S_IFDIR: 040000, // directory

lib/archivers/zip/zip-archive-entry.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,10 @@ ZipArchiveEntry.prototype.setTime = function(time) {
199199
};
200200

201201
ZipArchiveEntry.prototype.setUnixMode = function(mode) {
202-
mode &= ~constants.S_IFDIR;
203-
var extattr = 0;
204-
205-
if (!this.isDirectory()) {
206-
mode |= constants.S_IFREG;
207-
}
202+
mode &= ~constants.S_IFMT;
203+
mode |= this.isDirectory() ? constants.S_IFDIR : constants.S_IFREG;
208204

209-
extattr &= ~this.getExternalAttributes();
205+
var extattr = 0;
210206
extattr |= (mode << constants.SHORT_SHIFT) | (this.isDirectory() ? constants.S_DOS_D : constants.S_DOS_A);
211207

212208
this.setExternalAttributes(extattr);

test/zip-archive-entry.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ describe('ZipArchiveEntry', function() {
132132
entry.platform = 3;
133133
assert.equal(entry.getUnixMode(), 0777);
134134
});
135+
136+
it('should set proper external attributes for an unix directory', function () {
137+
entry = new ZipArchiveEntry('directory/');
138+
entry.setUnixMode(0777);
139+
140+
assert.ok(entry.getPlatform(), 3);
141+
assert.ok(entry.isDirectory());
142+
143+
var exattr = entry.getExternalAttributes() >> 16;
144+
assert.equal(exattr & 040000, 040000);
145+
});
135146
});
136147

137148
describe('#getVersionNeededToExtract', function() {
@@ -263,5 +274,4 @@ describe('ZipArchiveEntry', function() {
263274
assert.ok(entry.isDirectory());
264275
});
265276
});
266-
267277
});

0 commit comments

Comments
 (0)