https://bz.apache.org/bugzilla/show_bug.cgi?id=65497

            Bug ID: 65497
           Summary: Copy overwrite/granuarity broken
           Product: Ant
           Version: 1.10.11
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

After migrating an Ant script from Windows to Linux, it stopped working
correctly.
Analysis showed that the Copy task failed to copy a newer file over an older
one.

Source output/src.txt - 2021-08-12T14:33:36.221+02:00[Europe/Berlin]
Target output/tgt.txt - 2021-08-12T14:33:36.219+02:00[Europe/Berlin]

Clearly the src.txt file is newer and should be copied by the following task:
                <copy file="output/src.txt" tofile="output/tgt.txt" />
However it is not. On Linux, the default granularity is 1000, so this is
equivalent to:
                <copy file="output/src.txt" tofile="output/tgt.txt"
granularity="1000"/>

If you look at the implementation below, we can see that 
file.lastModified()-granularity
makes the actually newer file src.txt appear older then tgt.txt and therefore
no copy is made.

So to make the copy happen, I have to use overwrite. Howver this sommehow
contradicts the documentation
"Overwrite existing files even if the destination files are newer."
as in my case the source file is cleary newer.

If think the concept of overwrite/granularity is conceptually broken. 
With defaults of 1000 (UNIX) or 2000 (FAT), it basically implements
"By default, files are only copied if the source file is MORE THAN A FEW
SECONDS newer than the destination file".
So if you are working with short lived files, you basically have to use
overwrite for all copy operations - which should then probably be default but
prevent the optimization copy tries to do.

Unfortunately I see no easy solution without having too much impact.
If we could start from scratch, I would advise to make overwrite=true the
default behavior to get consisent behavior. If overwrite is manually set to
false, granularity should probably be 0 but could be changed as needed.

However I would suggest to make the documentation of the Copy task more
concise.


Please also correct @param granularity in SelectorUtils.isOutOfDate: "seconds"
-> "milliseconds"


Copy.java
        copySingleFile()
                if (forceOverwrite || !destFile.exists()
                || (file.lastModified() - granularity >
destFile.lastModified())) {
                    fileCopyMap.put(file.getAbsolutePath(), new String[]
{destFile.getAbsolutePath()});

SelectorUtils.java
     * @param granularity the amount in seconds of slack we will give in

    public static boolean isOutOfDate(File src, File target, int granularity) {
        return src.exists() && (!target.exists()
                || (src.lastModified() - granularity) > target.lastModified());
    }

FileUtils.java
    public static final long UNIX_FILE_TIMESTAMP_GRANULARITY = 1000;

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to