zeroturnaround / zt-zip

ZeroTurnaround ZIP Library
http://www.zeroturnaround.com/
Apache License 2.0
1.38k stars 251 forks source link

Preserve file permissions #52

Closed latuszek closed 10 years ago

latuszek commented 10 years ago

It would be nice if file permissions under Unix system could be preserved.

shelajev commented 10 years ago

Hi @seiyapl, it would be nice inceed. However, it's not that easy to implement. Obvious Unix vs. Windows permissions incompatibility aside (which means that we won't be able to make it work for cross-platform use), Java is not that good at setting file permissions.

Storing the mask of a file into an extra field on a ZipEntry is easy, however, obtaining it from the file and then setting it for unzipped file is harder. Especially Zt-Zip being Java 4 compatible.

We'll look into it anyway, but if you have a good idea about how to do it, please mention it. Maybe you can come up with a pull-request that shows what do you have in mind?

latuszek commented 10 years ago

Hi @shelajev. I know it won't be easy and I'm afraid I won't be helpful. I can only describe my use case. I'm using zt-zip in my autodeployment app which compress entire tomcat directory. However when I need to do rollback, file permissions are not restored. Currently I'm just changing them after unzipping calling unix "chmod" for all *.sh files.

toomasr commented 10 years ago

I'm not too pessimistic about this as Ant actually supports the basics. I think delivering something similar will make a lot of users happy.

nemecec commented 10 years ago

Well, one possibility would be to include a class to handle that, using Java7 API. So zt-zip would use that, but only when running on Java7.

toomasr commented 10 years ago

Yup, wouldn't be the only conditional feature, https://github.com/zeroturnaround/zt-zip/blob/master/src/main/java/org/zeroturnaround/zip/ZipFileUtil.java

shelajev commented 10 years ago

I'm taking this for myself. I'm looking into making it work on POSIX systems with modern enough Java version.

@seiyapl what version of Java do you use? I'll target that first and then we'll think how to improve the generic support later.

latuszek commented 10 years ago

@shelajev Here's my current version:

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

However, I think we will update to 1.7.0_60 soon.

toomasr commented 10 years ago

@shelajev be sure not to invent the wheel. The Unix and DOS permissions are in the external fields ( http://www.pkware.com/documents/casestudies/APPNOTE.TXT ) and there is an implementation at http://svn.apache.org/repos/asf/ant/core/tags/ANT_170/src/main/org/apache/tools/zip/ZipEntry.java

shelajev commented 10 years ago

I've put some time into investigating this. There's no easy solution in fact. Even with the Ant code at hand. The jdk's ZipOutputStream writes 0 for the external ettributes field of every entry. And it doesn't make it easy to extends the code.

Ant has their own ZipEntry implementation that has a field for the external attributes and their own ZipOutputStream to write the attributes to the correct place.

Just wanted to mention that I looked into that. Don't know how do we want to proceed yet.

toomasr commented 10 years ago

Why not take similar approach?

shelajev commented 10 years ago

Hm, indeed. I'll prepare a branch, we can look at how the code looks and decide then.

shelajev commented 10 years ago

Thanks, Viktor!

we need more tests for the permissions functionality, but the feature is implemented and all interested parties can try / test / use it.

hamzasAnwar commented 5 years ago

Hi, what is the status of this ? is it preserving unix permissions even if i extract it on windows? as i am looking for something which takes a zip file and remove some entries and recreates the zip file without loosing the unix permissions?

any help would be very appreciated.