Can Ant's tar task set a Linux file permission

2019-07-28 02:27发布

问题:

Starting with Ant 1.7, the TarFileSet is available which seems to allow file permission modifications in the tar archive.

Does this feature work platform-independent, so that I can for example create a tar file on Windows and set execution permissions for script files in this archive which will have this flag if the file is unpacked on Linux?

回答1:

Yes, you can set permissions using tarfileset, using the filemode and dirmode attributes. This works when creating tar archives, even on windows.

Rather annoyingly though, the untar task does not support the reverse operation that you might want:

File permissions will not be restored on extracted files.

But the permisions are restored fine if you use tar -xf, for example.