From 0edf3ca2524323395d9de340dc1927cb5f3ee267 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 19 May 2016 06:31:42 +0200 Subject: [PATCH] up-to-date check doesn't work properly on NTFS https://bz.apache.org/bugzilla/show_bug.cgi?id=59562 Patch by Gilles QUERRET --- CONTRIBUTORS | 1 + WHATSNEW | 4 ++++ contributors.xml | 4 ++++ src/etc/testcases/taskdefs/zip.xml | 19 +++++++++++++++++++ .../org/apache/tools/ant/taskdefs/Zip.java | 9 +++++++-- .../apache/tools/ant/taskdefs/ZipTest.java | 8 ++++++++ 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 74d6c636f..8e47e059f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -136,6 +136,7 @@ Georges-Etienne Legendre Gero Vermaas Gerrit Riessen Gilbert Rebhan +Gilles Querret Gilles Scokart Glenn McAllister Glenn Twiggs diff --git a/WHATSNEW b/WHATSNEW index 68338fca7..e01128c18 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -15,6 +15,10 @@ Fixed bugs: * 's quiet attribute was broken, it didn't suppress any messages. Bugzilla Report 59379 + * 's check whether an archive is already up-to-date failed on + NTFS filesystems and re-created archives more often than necessary. + Bugzilla Report 59562 + Other changes: -------------- diff --git a/contributors.xml b/contributors.xml index 85066b750..2bfa1b071 100644 --- a/contributors.xml +++ b/contributors.xml @@ -568,6 +568,10 @@ Gilbert Rebhan + + Gilles + Querret + Gilles Scokart diff --git a/src/etc/testcases/taskdefs/zip.xml b/src/etc/testcases/taskdefs/zip.xml index 4fa6de6c7..61a54a337 100644 --- a/src/etc/testcases/taskdefs/zip.xml +++ b/src/etc/testcases/taskdefs/zip.xml @@ -283,5 +283,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index ddc9bd493..91e28b9d6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -78,7 +78,11 @@ import org.apache.tools.zip.ZipOutputStream.UnicodeExtraFieldPolicy; */ public class Zip extends MatchingTask { private static final int BUFFER_SIZE = 8 * 1024; - private static final int ROUNDUP_MILLIS = 1999; // 2 seconds - 1 + /** + * The granularity of timestamps inside a ZIP archive. + */ + private static final int ZIP_FILE_TIMESTAMP_GRANULARITY = 2000; + private static final int ROUNDUP_MILLIS = ZIP_FILE_TIMESTAMP_GRANULARITY - 1; // CheckStyle:VisibilityModifier OFF - bc protected File zipFile; @@ -1548,7 +1552,8 @@ public class Zip extends MatchingTask { final Resource[] rs = selectFileResources(initial); Resource[] result = ResourceUtils.selectOutOfDateSources(this, rs, mapper, - getZipScanner()); + getZipScanner(), + ZIP_FILE_TIMESTAMP_GRANULARITY); if (!doFilesonly) { final Union u = new Union(); u.addAll(Arrays.asList(selectDirectoryResources(initial))); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java index 5a7a35905..efa9f77f8 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java @@ -297,4 +297,12 @@ public class ZipTest { } } + @Test + public void testRegexpMapper() throws IOException { + buildRule.executeTarget("testRegexpMapper1"); + File testFile = new File(buildRule.getOutputDir(), "regexp.zip"); + long l = testFile.lastModified(); + buildRule.executeTarget("testRegexpMapper2"); + assertEquals(l, testFile.lastModified()); + } }