Skip to content

Fix zip files created on Windows being unusable on Linux/MacOS (missing executable bits on directories) - #59

Open
Jimbly wants to merge 1 commit into
thejoshwolfe:masterfrom
Jimbly:fix_bad_execute_bits
Open

Fix zip files created on Windows being unusable on Linux/MacOS (missing executable bits on directories)#59
Jimbly wants to merge 1 commit into
thejoshwolfe:masterfrom
Jimbly:fix_bad_execute_bits

Conversation

@Jimbly

@Jimbly Jimbly commented May 10, 2020

Copy link
Copy Markdown

If a caller passes in a mode on the addEmptyDirectory() call, and that mode is taken directly from the (albeit platform-specific) fs.stat()'s mode, we end up creating zip files with directories that do not have the executable bit, which makes them completely unopenable on some platforms (MacOS Finder), and creates bad directory entries on others (Linux).

I also couldn't help but fix setFileAttributesMode to always set either S_IFDIR or S_IFREG, since it seemed really weird that it was only sometimes setting it (only if mode === null). This isn't to fix any observed bug, so I'd be perfectly fine sending a PR without that part of the change if needed for some reason, but I'm guessing all zip clients ignore those two flags anyway, so it probably doesn't matter ^_^.

This would resolve the following issues:
sindresorhus/gulp-zip#76
sindresorhus/gulp-zip#106
sindresorhus/gulp-zip#112

Some discussion about trying to work around it at a higher level here: https://github.com/sindresorhus/gulp-zip/pull/117 . Ending conclusion was that there's probably no reasonable situation in which we would want yazl to be creating zip files that cannot be opened on some platforms, so if it's writing platform-specific mode bits, it makes sense to massage them to be portable.

Comment thread test/test.js
throw new Error("unexpected entry fileName: " + entry.fileName + ", expected: " + expectedName);
}
var mode = entry.externalFileAttributes >>> 16;
if (/\/$/.test(entry.fileName)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (/\/$/.test(entry.fileName)) {
if (entry.fileName.startsWith('/')) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other spot in this file is using that regex to decide if it's a directory, so just matching that style, though I agree it's not particularly readable. So much so that your suggestion is actually backwards (should be fileName.endsWith('/')) ^_^. endsWith, however, is ES6+ only, and doesn't exist in Node v0.10, that this library is still being tested against.

@ijisol

ijisol commented Oct 17, 2024

Copy link
Copy Markdown

@Jimbly Hello, I'm forking yazl, would it be okay if I use the code from yours? I'm not sure how to interpret the license of a PR that hasn't been merged yet, so I'm asking first. If you don't want, I won't merge it. Thanks.

@Jimbly

Jimbly commented Oct 17, 2024

Copy link
Copy Markdown
Author

@ijisol Feel free! Since it's in my fork, which is public with the same license, seems you'd be safe to do so =). If you cherry-pick the commit, it'd even get author attribution in your history, but I don't care if my name's not on it anyway.

@ijisol

ijisol commented Oct 17, 2024

Copy link
Copy Markdown

@Jimbly I didn't know there was git-cherry-pick command. But since the code has changed so much, I'll just add your name to LICENSE.txt. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants