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 e53504e9 add test for copying a symlink (#564) e53504e9 is described below commit e53504e95dfe870f6b925d30f0e544eb0d85f14d Author: Elliotte Rusty Harold <elh...@users.noreply.github.com> AuthorDate: Tue Jan 23 20:58:40 2024 -0500 add test for copying a symlink (#564) --- .../java/org/apache/commons/io/FileUtilsTest.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java index 71811ac8..db55429f 100644 --- a/src/test/java/org/apache/commons/io/FileUtilsTest.java +++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java @@ -773,7 +773,7 @@ public class FileUtilsTest extends AbstractTempDirTest { assumeTrue(Files.exists(linkPath)); assumeTrue(Files.exists(linkPath, LinkOption.NOFOLLOW_LINKS)); - // Now copy sourceDirectory, including the broken link, to another directory + // Now copy sourceDirectory to another directory final File destination = new File(tempDirFile, "destination"); FileUtils.copyDirectory(sourceDirectory, destination); assertTrue(destination.exists()); @@ -1099,6 +1099,26 @@ public class FileUtilsTest extends AbstractTempDirTest { assertEquals(parFiles.size(), newFilePaths.size()); } + @Test + public void testCopyFile_symLink() throws Exception { + // Make a file + final File sourceDirectory = new File(tempDirFile, "source_directory"); + sourceDirectory.mkdir(); + final File targetFile = new File(sourceDirectory, "hello.txt"); + FileUtils.writeStringToFile(targetFile, "HELLO WORLD", "UTF8"); + + // Make a symlink to the file + final Path targetPath = targetFile.toPath(); + final Path linkPath = sourceDirectory.toPath().resolve("linkfile"); + Files.createSymbolicLink(linkPath, targetPath); + + // Now copy symlink to another directory + final File destination = new File(tempDirFile, "destination"); + FileUtils.copyFile(linkPath.toFile(), destination); + assertTrue(Files.isSymbolicLink(destination.toPath())); + } + + @Test public void testCopyFile1() throws Exception { final File destination = new File(tempDirFile, "copy1.txt");