Preserve file permissions when unzipping
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)
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. https://github.com/fhs/ZipFile.jl/blob/a599b0aac5d17403fdbbc4ea63612be299cf8417/src/ZipFile.jl#L358 and https://github.com/fhs/ZipFile.jl/blob/a599b0aac5d17403fdbbc4ea63612be299cf8417/src/ZipFile.jl#L343 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.