twolfson / grunt-zip

Zip and unzip files via a grunt plugin
MIT License
87 stars 19 forks source link

permissions are incorrect after unzip #37

Closed guy-mograbi-at-gigaspaces closed 9 years ago

guy-mograbi-at-gigaspaces commented 9 years ago

When I use unzip from command line, I get a file with permission 755.

when I use this grunt plugin, the permissions is different.

twolfson commented 9 years ago

What are the permissions you are seeing, what OS are you on, and what version of node are you running?

guy-mograbi-at-gigaspaces commented 9 years ago

i am seeing 664 instead of 775, i run on ubuntu with node 0.10.35.

twolfson commented 9 years ago

If you run the following, what do you get?

node --eval 'console.log(process.umask().toString(8))'
guy-mograbi-at-gigaspaces commented 9 years ago

I get 2

twolfson commented 9 years ago

Interesting, that should mean node would create files as 775. Can you try running the following commands and seeing what the permissions are?

node --eval "require('fs').writeFileSync('hello', 'world');"
ls -l hello
guy-mograbi-at-gigaspaces commented 9 years ago

-rw-rw-r-- 1 guym guym 5 Jul 29 06:39 hello

twolfson commented 9 years ago

Yep, that's 775. Have you tried uninstalling and reinstalling grunt?

guy-mograbi-at-gigaspaces commented 9 years ago

isn't that 664?

this is 775

guym@guym-pcu:~$ chmod 775 hello
guym@guym-pcu:~$ ll hello
-rwxrwxr-x 1 guym guym 5 Jul 29 06:39 hello*
twolfson commented 9 years ago

Oh, whoops. Right. It sounds like your umask is misconfigured somewhere. What's the current umask set to for your shell?

umask
guy-mograbi-at-gigaspaces commented 9 years ago
guym@guym-pcu:~$ umask
0002
twolfson commented 9 years ago

Oh, strange. Upon re-reading the documentation, node is using 0o666 as it's permissions -- on top of which the umask is applied leading to 0o664.

twolfson commented 9 years ago

https://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback

twolfson commented 9 years ago

Upon re-reading ZIP documentation, it looks like it doesn't store filesystem permissions so there is no way to "restore" them.

As an end user, I would prefer the 0o666 as the default case because I don't want any file to become executable upon extraction.

However, I think we should still support your use case. I am open to allowing users to override permissions for all files in a ZIP (e.g. options.mode). If that is outside of your use case though, I would suggest using something like:

https://www.npmjs.com/package/grunt-chmod

twolfson commented 9 years ago

Aaaand never mind again. It looks like we have UNIX permissions:

https://stuk.github.io/jszip/documentation/api_jszip/file_data.html

https://stuk.github.io/jszip/documentation/api_jszip/file_name.html

twolfson commented 9 years ago

Alright, I am heads down at the moment on another issue but I will take a look at adding support later tonight.

guy-mograbi-at-gigaspaces commented 9 years ago

ok.

fyi - I am using grunt-chmod for now.

and - the same issue exist when I naively implement the unzip task myself using node-unzip

https://github.com/EvanOxfeld/node-unzip/issues/6

twolfson commented 9 years ago

We have added support to save UNIX file permissions upon extraction in 0.17.0. Thanks for the bug report and quick responses!

guy-mograbi-at-gigaspaces commented 9 years ago

thank :smile:. tested and works great.