Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/generate/ZipFileWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ var generateUnixExternalFileAttr = function (unixPermissions, isDir) {
// 040775 => 0x41fd
// 0100664 => 0x81b4
result = isDir ? 0x41fd : 0x81b4;
} else if ((result & 0xF000) === 0) {
// The file type bits (S_IFMT) are missing, e.g. a bare "755" as
// shown in the documentation. Add them so tools that rely on the
// unix file type (zipinfo, ...) see a regular file / directory
// instead of an "unknown" type.
// 0040000 (S_IFDIR) => 0x4000
// 0100000 (S_IFREG) => 0x8000
result |= isDir ? 0x4000 : 0x8000;
}
return (result & 0xFFFF) << 16;
};
Expand Down
20 changes: 20 additions & 0 deletions test/asserts/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,24 @@ QUnit.module("permissions", function () {
JSZipTestUtils.testZipFile("permissions on windows : file created by winrar", "ref/permissions/windows_winrar.zip", assertDosPermissions);
JSZipTestUtils.testZipFile("permissions on windows : file created by winrar, reloaded", "ref/permissions/windows_winrar.zip", reloadAndAssertDosPermissions);

QUnit.test("unixPermissions without file type bits get a type (regular file / directory)", function (assert) {
var done = assert.async();
var zip = new JSZip();
// as documented, bare permissions without S_IFMT bits
zip.file("script.sh", "#!/bin/bash", {unixPermissions: "755"});
zip.file("data", "content", {unixPermissions: parseInt("644", 8)});
zip.file("dir/", null, {dir: true, unixPermissions: parseInt("755", 8)});
// a full mode (here a symlink) must be preserved unchanged, see #428
zip.file("link", "target", {unixPermissions: parseInt("120777", 8)});
zip.generateAsync({type: "string", platform: "UNIX"})
.then(JSZip.loadAsync)
.then(function (reloaded) {
assert.equal(reloaded.files["script.sh"].unixPermissions.toString(8), "100755", "the file gets the regular file type bit");
assert.equal(reloaded.files["data"].unixPermissions.toString(8), "100644", "the file gets the regular file type bit");
assert.equal(reloaded.files["dir/"].unixPermissions.toString(8), "40755", "the folder gets the directory type bit");
assert.equal(reloaded.files["link"].unixPermissions.toString(8), "120777", "an existing file type is left untouched");
done();
})["catch"](JSZipTestUtils.assertNoError);
});

});