Skip to content

Commit

Permalink
[MSHARED-1107] Make copyFile succeed with source file having
Browse files Browse the repository at this point in the history
lastModified() = 0

Also check for existence of destination file
  • Loading branch information
kwin committed Jul 25, 2022
1 parent 2bf1e03 commit 45d4695
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ public static void copyFile( @Nonnull File from, @Nonnull File to, @Nullable Str
{
if ( wrappers == null || wrappers.length == 0 )
{
if ( overwrite || to.lastModified() < from.lastModified() )
if ( overwrite || !to.exists() | to.lastModified() < from.lastModified() )
{
copyFile( from, to );
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,30 @@ public void copyFileWithNoFiltersAndNoDestination()
assertFileContent( to, "Hello World!" );
}

@Test
public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination()
throws Exception
{
File from = write(
"from.txt",
MODIFIED_YESTERDAY,
"Hello World!"
);
File to = new File(
tempFolder.getRoot(),
"to.txt"
);

from.setLastModified( 0 );
FileUtils.copyFile( from, to, null, ( FileUtils.FilterWrapper[] ) null);

assertTrue(
"to.txt did not exist so should have been written",
to.lastModified() >= MODIFIED_TODAY
);
assertFileContent( to, "Hello World!" );
}

@Test
public void copyFileWithNoFiltersAndOutdatedDestination()
throws Exception
Expand Down

0 comments on commit 45d4695

Please sign in to comment.