Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the Ant tar task and preserve file permissions?

Of course it can be done using the exec task, but my question is:

Is it possible to do it using the tar task?

like image 449
givanse Avatar asked Oct 04 '09 20:10

givanse


2 Answers

I don't think there is a way to retain existing permissions, per this note from the copy task:

Unix Note: File permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes. If you need a permission-preserving copy function, use <exec executable="cp" ... > instead.

However the tar task can take one or more tarfileset elements. The tarfileset can be defined with a filemode and/or dirmode attribute to specify the unix permissions. If you specify multiple includes matching only those files to get each set of required permissions, the files in that set will be included with those permissions.

like image 193
Rich Seller Avatar answered Oct 15 '22 09:10

Rich Seller


It is impossible. This lack of permission makes ant tar task almost useless for me. There's no way to do it without executing the operating system tar with the exec task:

    <exec executable="tar" output="/dev/null" os="Linux">
        <arg value="--exclude-from=files_to_exclude.txt"/>
        <arg value="-cvz"/>
        <arg value="--file=${file.tar}"/>
        <arg value="."/>
    </exec>

There are gnu tar binaries for almost all operating systems known to man. Put one of them in your version control system and use it depending in your operating system. Yes, Ant will need to fork a process every time it is run.

like image 30
neves Avatar answered Oct 15 '22 09:10

neves