Permissions for files are not saved, and after zip

I try to maintain certain file permissions after they are encrypted, however I noticed that the file permissions are not saved. No matter what I do, the file permissions for the unpacked file are always rw-rr--.

I have tried the following things:

  • By setting umask to 0027 in my bash_profile, I noticed that by default, the newly created zip file creates permissions for the "0022" aka rw-rr- files.

  • I tried installing AsiExtraField with 777 mode and binding it to ZipArchiveEntry, however it does not seem to affect perms.

ZipArchiveEntry entry = new ZipArchieveEntry (file name); AsiExtrafield temp = new AsiExtraField (); temp.setMode (777); entry.addAsFirstExtraField (temperature); zipoutputstream.putNextEntry (record);

  • For ZipEntries, I tried to set UnixMode () to 777, however, all the unpacked files have the resolution rw-rr--.
ZipEntry entry = new ZipEntry(filename); entry.setUnixMode(777); zipoutputstream.putNextEntry(entry); 
  • Finally, I explicitly set the file permissions of the target file before it gets stuck, however perms files are not copied.
 Runtime.getRuntime.exec("chmod 777" + file.getCanonicalPath()): ZipEntry entry = new ZipEntry(filename); zipoutputstream.putNextEntry(entry); 

Help rate!

+4
source share
2 answers

The ZIP format can store unix permissions in the "external attributes" field inside the ZIP header.

As an aside, I did this for ZIP files created using the maven-assembly-plugin module using <fileMode>0755</fileMode> in the assembly descriptor.

To programmatically extract an archive from Java while maintaining permissions, there is a good commons-compress cover called jarchivelib that supports several formats, including ZIP, tar.gz. It extracts the correct persistence of UNIX permissions.

+2
source

It looks like you need to try a different archive format. Maybe tar --preserve-permissions .

Another option is to save the permissions separately and reapply them when unpacking. You can add the .saved_permissions file to the archive. There are several sample scripts that can do this at fooobar.com/questions/300032 / ....

0
source

Source: https://habr.com/ru/post/1493736/


All Articles