Skip to content

Commit 0430a8e

Browse files
committed
Fix permissions when writing folders
A folder in Zip always have the DOS attribute set and, shifted by 16 bits, there may be the UNIX flags made of the rights (including the executable bit to cross the folder) and the inode type.
1 parent f5992a3 commit 0430a8e

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

lib/core/zip-writer.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,9 @@ async function addFile(zipWriter, name, reader, options) {
251251
name += DIRECTORY_SIGNATURE;
252252
}
253253
if (externalFileAttributes === 0) {
254-
if (msDosCompatible) {
255-
externalFileAttributes = FILE_ATTR_MSDOS_DIR_MASK;
256-
} else {
257-
externalFileAttributes = FILE_ATTR_UNIX_TYPE_DIR << 16;
254+
externalFileAttributes = FILE_ATTR_MSDOS_DIR_MASK;
255+
if (!msDosCompatible) {
256+
externalFileAttributes |= (FILE_ATTR_UNIX_TYPE_DIR | FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_DEFAULT_MASK) << 16;
258257
}
259258
}
260259
} else if (!msDosCompatible && externalFileAttributes === 0) {

tests/all/test-directory.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ async function test() {
1818
await zipWriter.close();
1919
const zipReader = new zip.ZipReader(new zip.BlobReader(await blobWriter.getData()));
2020
const entries = await zipReader.getEntries();
21-
if (entries[0].directory && entries[0].filename == FOLDER_NAME) {
21+
if (entries[0].directory && entries[0].filename == FOLDER_NAME &&
22+
(entries[0].externalFileAttributes & 0xffff) == 0x10 &&
23+
entries[0].externalFileAttributes >> 16 == 0o40755) {
2224
if (!entries[1].directory && entries[1].filename == FILENAME) {
2325
const text = await entries[1].getData(new zip.TextWriter());
2426
await zipReader.close();

0 commit comments

Comments
 (0)