From 6f53345b8b8f3149b8c0f601c13e2380772fde32 Mon Sep 17 00:00:00 2001 From: Andreas Kluth Date: Wed, 25 Apr 2018 17:28:05 +0200 Subject: [PATCH 1/2] Files created on 1970-01-01 0000.0 are never copied when the target is not present. --- .../org/codehaus/plexus/util/FileUtils.java | 15 ++++++++++----- .../org/codehaus/plexus/util/FileUtilsTest.java | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index 6b910b29..3dc0af41 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -1164,7 +1164,7 @@ private static void doCopyFileUsingNewIO( File source, File destination ) public static boolean copyFileIfModified( final File source, final File destination ) throws IOException { - if ( destination.lastModified() < source.lastModified() ) + if ( isSourceNewerThanDestination( source, destination ) ) { copyFile( source, destination ); @@ -2289,7 +2289,8 @@ public static File createTempFile( String prefix, String suffix, File parentDir } /** - * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() + * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified(), + * if the files were both created on 1970-01-01 : 0000.00 * * @param from the file to copy * @param to the destination file @@ -2309,8 +2310,8 @@ public static abstract class FilterWrapper } /** - * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if - * overwrite is true + * If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified(), + * if the files were both created on 1970-01-01 : 0000.00 or if overwrite is true * * @param from the file to copy * @param to the destination file @@ -2367,13 +2368,17 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[ } else { - if ( to.lastModified() < from.lastModified() || overwrite ) + if ( isSourceNewerThanDestination( from, to ) || overwrite ) { copyFile( from, to ); } } } + private static boolean isSourceNewerThanDestination( File source, File destination ) { + return ( destination.lastModified() == 0L && source.lastModified() == 0L ) || destination.lastModified() < source.lastModified(); + } + /** * Note: the file content is read with platform encoding * diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index 2ba6682b..d6851feb 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -439,6 +439,23 @@ public void testCopyIfModifiedWhenSourceIsOlder() assertFalse( "Source file should not have been copied.", FileUtils.copyFileIfModified( source, destination ) ); } + public void testCopyIfModifiedWhenSourceHasZeroDate() + throws Exception + { + FileUtils.forceMkdir( new File( getTestDirectory() + "/temp" ) ); + + // Source modified on 1970-1-1 0000.0 + File source = new File( getTestDirectory(), "copy1.txt" ); + FileUtils.copyFile( testFile1, source ); + source.setLastModified( 0L ); + + // A non existing destination + File destination = new File( getTestDirectory(), "/temp/copy1.txt" ); + + // Should copy the source to the non existing destination. + assertTrue( "Source file should have been copied.", FileUtils.copyFileIfModified( source, destination ) ); + } + // forceDelete public void testForceDeleteAFile1() From 6d51bb4ae55ff9ac27aef3a4b0e03404ffacc188 Mon Sep 17 00:00:00 2001 From: Andreas Kluth Date: Wed, 25 Apr 2018 18:15:41 +0200 Subject: [PATCH 2/2] Use openjdk7 instead of oraclejdk7 as oraclejdk7 is not supported by travis any more. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 949e94b8..13f6528e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: java jdk: - - oraclejdk7 + - openjdk7 - oraclejdk8 # No need for preliminary install step.