Skip to content

Commit da11090

Browse files
committed
[MSHARED-1112] Test case for NoSuchFileException while copying symbolic
link with relative non-existing target
1 parent 28c8ce6 commit da11090

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import java.io.Writer;
4040
import java.net.URL;
4141
import java.nio.file.Files;
42+
import java.nio.file.Path;
43+
import java.nio.file.Paths;
4244
import java.util.Arrays;
4345
import java.util.HashMap;
4446
import java.util.HashSet;
@@ -445,15 +447,14 @@ public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination()
445447
{
446448
File from = write(
447449
"from.txt",
448-
MODIFIED_YESTERDAY,
450+
0,
449451
"Hello World!"
450452
);
451453
File to = new File(
452454
tempFolder.getRoot(),
453455
"to.txt"
454456
);
455457

456-
from.setLastModified( 0 );
457458
FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null );
458459

459460
assertTrue(
@@ -463,6 +464,28 @@ public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination()
463464
assertFileContent( to, "Hello World!" );
464465
}
465466

467+
@Test
468+
public void copyRelativeSymbolicLinkFileWithNonExistingTargetWithNoFiltersAndNoDestination()
469+
throws Exception
470+
{
471+
472+
File target = write(
473+
"target.txt",
474+
MODIFIED_YESTERDAY,
475+
"Hello World!"
476+
);
477+
// must be a relative symbolic link
478+
Path from = Files.createSymbolicLink( new File(tempFolder.getRoot(), "symLink").toPath(), Paths.get( "target.txt" ) );
479+
File to = new File(
480+
tempFolder.newFolder( "destDirectory" ),
481+
"toSymLink"
482+
);
483+
// this create a symlink in a newfolder pointing to a non-existing relative target "./target.txt"
484+
FileUtils.copyFile( from.toFile(), to, null, (FileUtils.FilterWrapper[]) null );
485+
486+
// this should not fail
487+
}
488+
466489
@Test
467490
public void copyFileWithNoFiltersAndOutdatedDestination()
468491
throws Exception

0 commit comments

Comments
 (0)