Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve file permissions when unzipping #90

Open
AnHeuermann opened this issue Aug 1, 2022 · 1 comment
Open

Preserve file permissions when unzipping #90

AnHeuermann opened this issue Aug 1, 2022 · 1 comment

Comments

@AnHeuermann
Copy link

Hey,

I'm using ZipFile.jl to unzip some files on a Linux system. Is it possible to preserve the permissions of the original files?
I can't find permissions in ZipFile.ReadableFile and therefore when writing the files I don't know which files need only read/write permissions and which additional execute permissions.

I guess one would need to add something to ZipFile.ReadableFile and get the mode from zlib. But I'm note sure if zlib offers a function to do that.

How to reproduce

Create a zip file

$ mkdir myZip
$ touch myZip/script.sh
$ chmod +rwx myZip/script.sh
$ ls -la myZip/script.sh 
-rwxrwxr-x 1 username groupname 0 Aug  1 16:33 myZip/script.sh
$ zip myZip -r
$ zip -r myZip.zip myZip/

unzip preserves permissions

$ unzip myZip.zip -d unzipped/
$ ls -la unzipped/myZip/script.sh 
-rwxrwxr-x 1 username groupname 0 Aug  1 16:33 unzipped/myZip/script.sh

Where could I find file permissions

julia> using ZipFile
julia> archive = ZipFile.Reader("myZip.zip")
ZipFile.Reader for IOStream(<file myZip.zip>) containing 2 files:

uncompressedsize method  mtime            name
----------------------------------------------
               0 Store   2022-08-01 16-33 myZip/
               0 Store   2022-08-01 16-33 myZip/script.sh
julia> archive.files[2]
ZipFile.ReadableFile(name=myZip/script.sh, method=Store, uncompresssedsize=0, compressedsize=0, mtime=1.659364424e9)
@nhz2
Copy link

nhz2 commented Apr 24, 2023

Unfortunately, the official zip file spec doesn't directly mention a cross-platform way to specify a file is executable, so this might be tricky to do. Zip files contain a 32-bit external file attributes field for each file, but this field differs for each OS.

skip(io, 2+2+4)
and
skip(io, 2+2)
seem to be where the fields are that might specify file permissions and OS. They are currently ignored. If the version made is UNIX, I found this link https://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute that describes how to read the permissions.

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

No branches or pull requests

2 participants