2012-04-03 3 views
5

나는 <exec executable="cp" failonerror="true">을 사용할 수 있다는 것을 알고 있지만 실제로 모든 것을 사용할 수있는 모든 운영 체제 (또는 적어도 대부분)에서 호출 할 수있는 작업을 갖고 있습니다. 의 속성을 copy으로 변경하지만 유닉스에 대한 권한을 앗아가는 것은 아닙니다.사용 권한을 잃지 않고 복사 할 수있는 개미 작업이 있습니까

이미 해결책이 있는지 궁금하거나 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> 

나는 이것을 작성했습니다.

<!-- ==================================================================== --> 
<!-- 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> 

답변

3

저는 하나도 모릅니다. Ant의 문서에서 언급했듯이 JRE에서 파일 사용 권한을 조작 할 메커니즘이 없기 때문입니다. Ant Copy task

자바 7은 이런 종류의 일을 훨씬 잘 지원합니다. 따라서 향후 개미판에서 가능할 것입니다. 개미가 버전 1.9의 Java 5로 옮겨 가고 있다고 생각하기 때문에 이것은 매우 오랜 시간이 걸릴 것입니다.

OS 기반의 특정 명령을 조건부로 실행하여 원하는 동작을 시뮬레이트 할 수있을 것 같습니까?

관련 문제