是否有可以复制而不会丢失权限的ant任务

jgr*_*tty 6 ant file-permissions copy

我知道我可以<exec executable="cp" failonerror="true">,但是,我真的宁愿有一个任务,我可以从任何可以使用所有(或至少大多数)属性的操作系统调用copy,但不会删除权限UNIX.

我想知道是否已有解决方案,或者我是否必须自己编写解决方案copy2.

因为我有点害怕,没有什么"现成的".我们有这个代码,但它只处理目录到目录副本或文件到文件副本,具有自定义属性,并且不执行任何其他整洁的复制操作.

<!-- ==================================================================== -->
<!-- Copy files from A to B                                               -->
<!-- <copy> would do this job, if it weren't such a useless pile of fail  -->
<!-- and could manage to preserve execute bits on Linux                   -->
<!-- ==================================================================== -->
<macrodef name="internal-copydir">
    <attribute name="fromdir" default="NOT SET" />
    <attribute name="todir" default="NOT SET" />
    <sequential>
        <if>
            <os family="windows" />
            <then>
                <copy todir="@{todir}">
                    <fileset dir="@{fromdir}" />
                </copy>
            </then>
            <else>
                <exec executable="rsync" failonerror="true">
                    <arg value="-a" />
                    <arg value="@{fromdir}/" />
                    <arg value="@{todir}/" />
                </exec>
            </else>
        </if>
    </sequential>
</macrodef>

<!-- ==================================================================== -->
<!-- Copy file from A to B                                                -->
<!-- <copy> would do this job, if it weren't such a useless pile of fail  -->
<!-- and could manage to preserve execute bits on Linux                   -->
<!-- ==================================================================== -->
<macrodef name="internal-copyfile">
    <attribute name="file" default="NOT SET" />
    <attribute name="tofile" default="NOT SET" />
    <sequential>
        <if>
            <os family="windows" />
            <then>
                <copy file="@{file}" tofile="@{tofile}"/>
            </then>
            <else>
                <exec executable="cp" failonerror="true">
                    <arg value="@{file}" />
                    <arg value="@{tofile}" />
                </exec>
            </else>
        </if>
    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

我也写了这个.

<!-- ==================================================================== -->
<!-- Copy file to a directory                                             -->
<!-- <copy> would do this job, if it weren't such a useless pile of fail  -->
<!-- and could manage to preserve execute bits on Linux                   -->
<!-- ==================================================================== -->
<macrodef name="internal-copyfiletodir">
    <attribute name="file" default="NOT SET" />
    <attribute name="todir" default="NOT SET" />
    <sequential>
        <if>
            <os family="windows" />
            <then>
                <copy file="@{file}" todir="@{todir}"/>
            </then>
            <else>
                <exec executable="cp" failonerror="true">
                    <arg value="@{file}" />
                    <arg value="@{todir}/" />
                </exec>
            </else>
        </if>
    </sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)

gro*_*odt 5

我不知道一个。如Ant文档中所述,这是因为JRE中没有机制来操纵文件权限。蚂蚁复制任务

Java 7为这种事情带来了更好的支持,因此也许在将来的Ant版本中这将成为可能。这可能会花费很长时间,因为我认为Ant仅会针对1.9版迁移到Java 5。

我猜您可能可以通过基于OS的条件运行特定于OS的命令来模拟所需的行为?