Reputation: 1595
I've come across an issue with Ant's Sync
task where files are being copied unnecessarily. The goal is to update everything in the ${destination}
directory with the contents of the ${source}
directory, even if the file in the ${destination}
is newer. Based on Ant's documentation, I've added an overwrite
attribute to to ensure the ${destination}
is overwritten.
<target name="test">
<sync todir="${destination}" overwrite="true" granularity="5000">
<fileset dir="${source}">
</fileset>
</sync>
</target>
This task correctly overwrites the ${destination}
, but the file is always copied, even when the source and destination are identical. This leads to a lot of unnecessary traffic.
Based on the documentation, I attempted to configure the granularity
attribute, but this doesn't appear to have any effect. I'm also running this test between two directories on the same machine, so I wouldn't expect timestamp differences (certainly not of more than 5 seconds).
Any thoughts about why the Sync
task and overwrite
attribute function in this way? Are there any solutions using the default set of Ant tasks to prevent the unnecessary file copying?
Upvotes: 0
Views: 156
Reputation: 4319
If you use the sync task with overwrite="true", you will get this behavior.
You could use it with overwrite="false", and then follow up with a copy task that only copy the files that are existing but different, with the different selector, e.g.:
<copy todir="${destination}">
<fileset dir="${source}">
<different targetdir="${destination}" ignoreFileTimes="true"/>
</fileset>
</copy>
Upvotes: 1