This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new d7fa1f6 Address -1 from Sebb by only stamping target file with the source's timestamp if requested and ignoring test assertions on Windows since the JRE Files class copies the last modified time by default for me on Microsoft Windows [Version 10.0.16299.1992] and OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01). d7fa1f6 is described below commit d7fa1f624ec0ba09cd3cbfba9913d51afc8f59c3 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Mon Aug 10 14:42:38 2020 -0400 Address -1 from Sebb by only stamping target file with the source's timestamp if requested and ignoring test assertions on Windows since the JRE Files class copies the last modified time by default for me on Microsoft Windows [Version 10.0.16299.1992] and OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01). --- src/main/java/org/apache/commons/io/FileUtils.java | 3 ++- .../java/org/apache/commons/io/FileUtilsTestCase.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 0f0f5d0..e4bb062 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -1394,6 +1394,7 @@ public class FileUtils { final Path srcPath = srcFile.toPath(); final Path destPath = destFile.toPath(); + // On Windows, the last modified time is copied by default. Files.copy(srcPath, destPath, copyOptions); // TODO IO-386: Do we still need this check? @@ -1401,7 +1402,7 @@ public class FileUtils { // TODO IO-386: Do we still need this check? checkEqualSizes(srcFile, destFile, srcFile.length(), destFile.length()); - return destFile.setLastModified(preserveFileDate ? srcFile.lastModified() : System.currentTimeMillis()); + return preserveFileDate ? destFile.setLastModified(srcFile.lastModified()) : true; } //----------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java index cc8ed7d..c33d1fc 100644 --- a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java +++ b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java @@ -55,6 +55,7 @@ import java.util.zip.Checksum; import org.apache.commons.io.filefilter.NameFileFilter; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.commons.io.test.TestUtils; +import org.apache.commons.lang3.SystemUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -1230,14 +1231,17 @@ public class FileUtilsTestCase { // destination file time should not be less than this (allowing for granularity) final long now = System.currentTimeMillis() - 1000L; + // On Windows, the last modified time is copied by default. FileUtils.copyFile(testFile1, destFile, false); assertTrue(destFile.exists(), "Check Exist"); assertEquals(testFile1Size, destFile.length(), "Check Full copy"); final long destLastMod = getLastModifiedMillis(destFile); final long unexpected = getLastModifiedMillis(testFile1); - assertNotEquals(unexpected, destLastMod, - "Check last modified date not same as input, delta " + (destLastMod - unexpected)); - assertTrue(destLastMod > now, destLastMod + " > " + now); + if (!SystemUtils.IS_OS_WINDOWS) { + assertNotEquals(unexpected, destLastMod, + "Check last modified date not same as input, delta " + (destLastMod - unexpected)); + assertTrue(destLastMod > now, destLastMod + " > " + now); + } } @Test @@ -1407,10 +1411,13 @@ public class FileUtilsTestCase { final File targetFile = new File(targetDirectory, "hello.txt"); // Test with preserveFileDate disabled + // On Windows, the last modified time is copied by default. FileUtils.copyDirectory(source, target, false); assertNotEquals(DATE1, getLastModifiedMillis(target)); assertNotEquals(DATE2, getLastModifiedMillis(targetDirectory)); - assertNotEquals(DATE3, getLastModifiedMillis(targetFile)); + if (!SystemUtils.IS_OS_WINDOWS) { + assertNotEquals(DATE3, getLastModifiedMillis(targetFile)); + } FileUtils.deleteDirectory(target); // Test with preserveFileDate enabled