Skip to content

Commit 21a435d

Browse files
committed
Preserve unix mode and fix symlinks
1 parent c6198ed commit 21a435d

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

lib/archivers/zip/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ module.exports = {
6868
S_DOS_S: 4, // 04 System
6969
S_DOS_H: 2, // 02 Hidden
7070
S_DOS_R: 1 // 01 Read Only
71-
};
71+
};

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ ZipArchiveEntry.prototype.getTimeDos = function() {
110110
};
111111

112112
ZipArchiveEntry.prototype.getUnixMode = function() {
113-
return this.platform !== constants.PLATFORM_UNIX ? 0 : ((this.getExternalAttributes() >> constants.SHORT_SHIFT) & constants.SHORT_MASK) & constants.MODE_MASK;
113+
return this.platform !== constants.PLATFORM_UNIX ? 0 : ((this.getExternalAttributes() >> constants.SHORT_SHIFT) & constants.SHORT_MASK);
114114
};
115115

116116
ZipArchiveEntry.prototype.getVersionNeededToExtract = function() {
@@ -200,7 +200,6 @@ ZipArchiveEntry.prototype.setTime = function(time, forceLocalTime) {
200200
};
201201

202202
ZipArchiveEntry.prototype.setUnixMode = function(mode) {
203-
mode &= ~constants.S_IFMT;
204203
mode |= this.isDirectory() ? constants.S_IFDIR : constants.S_IFREG;
205204

206205
var extattr = 0;
@@ -220,9 +219,9 @@ ZipArchiveEntry.prototype.isDirectory = function() {
220219
};
221220

222221
ZipArchiveEntry.prototype.isUnixSymlink = function() {
223-
return (this.getUnixMode() & constants.S_IFLINK) === constants.S_IFLINK;
222+
return (this.getUnixMode() & constants.S_IFMT) === constants.S_IFLNK;
224223
};
225224

226225
ZipArchiveEntry.prototype.isZip64 = function() {
227226
return this.csize > constants.ZIP64_MAGIC || this.size > constants.ZIP64_MAGIC;
228-
};
227+
};

test/zip-archive-entry.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('ZipArchiveEntry', function() {
131131
entry.mode = 0777;
132132
entry.exattr = 2180972576;
133133
entry.platform = 3;
134-
assert.equal(entry.getUnixMode(), 0777);
134+
assert.equal(entry.getUnixMode(), 0100777);
135135
});
136136

137137
it('should set proper external attributes for an unix directory', function () {
@@ -269,6 +269,15 @@ describe('ZipArchiveEntry', function() {
269269
entry.setUnixMode(0777);
270270
assert.propertyVal(entry, 'exattr', 2180972576);
271271
assert.propertyVal(entry, 'mode', 0777);
272+
assert.equal(entry.getUnixMode(), 0100777);
273+
274+
});
275+
276+
it('should also preserve filetype information', function() {
277+
entry.setUnixMode(0120755);
278+
assert.propertyVal(entry, 'exattr', 2716663840);
279+
assert.propertyVal(entry, 'mode', 0755);
280+
assert.equal(entry.getUnixMode(), 0120755);
272281
});
273282
});
274283

@@ -286,4 +295,4 @@ describe('ZipArchiveEntry', function() {
286295
assert.ok(entry.isDirectory());
287296
});
288297
});
289-
});
298+
});

0 commit comments

Comments
 (0)