Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I process only files that have changed?

Tags:

ant

At the moment I'm doing this:

<delete dir="${RSA.dir}/file1" />
<copy todir="${RSA.dir}/file1" >
    <fileset dir="${CLEARCASE.dir}/file1" />            
</copy>

and repeating the same thing for other files - but it takes a long time.

I only want to delete and copy files that have been updated, with their modified date in clearcase later than that in RSA.

How can I do that?


2 Answers

Look into the sync task.

If you want to do it based on file contents, and ignore the timestamp, I think this macro will do that:

<macrodef name="mirror" description="Copy files only if different; remove files that do not exist in dir. This works similiar to robocopy /MIR." >
    <attribute name="dir"/>
    <attribute name="todir"/>
    <sequential>
        <copy overwrite="true" todir="@{todir}">
            <fileset dir="@{dir}">
                <different targetdir="${todir}"/>
            </fileset>
        </copy>
        <delete includeemptydirs="true">
            <fileset dir="@todir}">
                <present targetdir="${dir}" present="srconly"/>
            </fileset>                
        </delete>
    </sequential>
</macrodef>
like image 170
Douglas Borg Avatar answered Nov 24 '25 19:11

Douglas Borg


You need to use a selector on a FileSet. Something like this:

<fileset dir="${your.working.dir}/src/main" includes="**/*.java">
    <different targetdir="${clean.clearcase.checkout}/src/main"
        ignoreFileTimes="false"
        ignoreContents="true" />
</fileset>

That compares your working dir to a clean checkout you have elsewhere, and returns the files whose last modified times have changed. You can use the fileset as the argument for a <delete> or a <copy>.

like image 34
Ry4an Brase Avatar answered Nov 24 '25 21:11

Ry4an Brase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!