2011-05-09 5 views
7

정말 개미 '동기화'작업을 좋아하지만 원본 폴더에서 대상 폴더로 파일을 복사할지 여부에 따라 파일을 복사해야합니다. 대상 파일의 내용이 파일 수정 날짜 (현재 '동기화')를 확인하는 대신 원본 파일의 내용과 일치합니다. 이것을 달성 할 방법이 있습니까? 나는 파일 콘텐트를위한 Ant 콤퍼레이터와 편리한 체크섬 태스크를 발견했다.Ant의 'sync'작업을 사용하지만 파일 내용을 기반으로하는 방법

감사합니다.

+0

적 동기화 작업을 수행하기 위해 rsync를 호출 고려 :

여기 macrodef의 새로운 코드는? – ewh

+1

아이디어를 주셔서 감사합니다. 가능한 경우 개미 기반 솔루션을 찾고있었습니다. –

답변

5

은 오히려 다른 대답에 다른 선택에보다 수정 선택기를 사용하지 않고 타임 스탬프보다는 내용에 따라 다른 하나 개의 위치를 ​​동기화하기위한 작업입니다 파일의 차이를 계산하는 방법을보다 효율적으로 관리 제공 : 당신이 양방향 동기화를 원하는 경우는이 B-에서 사본을 삭제 대체 할 수있다, (동기화 A-> B)이 바 미러 foo를 만드는 것을

<project name="Demo" default="newSync"> 
    <description> 
    Sync from ${foo} to ${bar} 
    </description> 

    <macrodef name="syncContents"> 
    <attribute name="from"/> 
    <attribute name="to"/> 
    <sequential> 
     <fileset id="selectCopyFiles" dir="@{from}"> 
     <modified algorithm="hashvalue"/> 
     </fileset> 
     <fileset id="selectDeleteFiles" dir="@{to}"> 
     <not> 
      <present targetdir="@{from}"/> 
     </not> 
     </fileset> 

     <copy overwrite="true" todir="@{to}"> 
     <fileset refid="selectCopyFiles"/> 
     </copy> 
     <delete includeEmptyDirs="true"> 
     <fileset refid="selectDeleteFiles"/>    
     </delete> 
    </sequential> 
    </macrodef> 

    <target name="newSync"> 
    <syncContents from="${foo}" to="${bar}"/> 
    </target> 
</project> 

주> A로 변경하고 두 위치의 동일한 파일에 대한 변경 사항을 처리하기위한 concat 태스크를 제공하십시오.

1

이 작업을 해주셔서 감사합니다.

그러나 selectCopyFiles 파일 세트가 올바르지 않습니다. selectDeleteFiles 파일 세트에 대한 또 다른 솔루션이 있습니다.

<macrodef name="syncContents"> 
    <attribute name="from"/> 
    <attribute name="to"/> 
    <sequential> 
     <echo>syncContents  : @{from} -> @{to}</echo> 
     <fileset id="selectCopyFiles" dir="@{from}"> 
      <different targetdir="@{to}" 
      ignoreFileTimes="true"/> 
     </fileset> 
     <fileset id="selectDeleteFiles" dir="@{to}"> 
      <present present="srconly" targetdir="@{from}"/> 
     </fileset> 

     <copy overwrite="true" todir="@{to}" preservelastmodified="true" verbose="true"> 
      <fileset refid="selectCopyFiles"/> 
     </copy> 
     <delete includeEmptyDirs="true" verbose="true"> 
      <fileset refid="selectDeleteFiles"/> 
     </delete> 
     <echo>End syncContents : @{from} -> @{to}</echo> 
    </sequential> 
</macrodef> 
관련 문제