Skip to content

Commit 3988bd0

Browse files
committed
[IO-807] Copy symlinks, not the files the symlinks point to #558
- Use diamond notation - Reuse PathUtils.EMPTY_COPY_OPTIONS - Refactor calls to toPath()
1 parent ec4144b commit 3988bd0

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The <action> type attribute can be add,update,fix,remove.
9191
<action dev="ggregory" type="fix" due-to="Sylwester Lachiewicz, Gary Gregory">XmlStreamReader can't parse an XML document with a multi-line prolog #550.</action>
9292
<action dev="ggregory" type="fix" due-to="Andreas Hubold, Gary Gregory">XmlStreamReader can't parse XML an document with an external parsed entity prolog.</action>
9393
<action dev="ggregory" type="fix" issue="IO-836" due-to="Elliotte Rusty Harold">Update FileNameUtils Javadoc #554.</action>
94+
<action dev="ggregory" type="fix" issue="IO-807" due-to="Jordi Sola, Elliotte Rusty Harold">Copy symlinks, not the files the symlinks point to #558.</action>
9495
<!-- Add -->
9596
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileName(Path, Function&lt;Path, R&gt;).</action>
9697
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileNameString().</action>

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,14 +845,15 @@ public static void copyFile(final File srcFile, final File destFile, final boole
845845
requireCanWrite(destFile, "destFile");
846846
}
847847

848-
final boolean isSymLink = Files.isSymbolicLink(srcFile.toPath());
848+
final Path srcPath = srcFile.toPath();
849+
final boolean isSymLink = Files.isSymbolicLink(srcPath);
849850
if (isSymLink && !Arrays.asList(copyOptions).contains(LinkOption.NOFOLLOW_LINKS)) {
850-
final List<CopyOption> list = new ArrayList<CopyOption>(Arrays.asList(copyOptions));
851+
final List<CopyOption> list = new ArrayList<>(Arrays.asList(copyOptions));
851852
list.add(LinkOption.NOFOLLOW_LINKS);
852-
copyOptions = list.toArray(new CopyOption[0]);
853+
copyOptions = list.toArray(PathUtils.EMPTY_COPY_OPTIONS);
853854
}
854855

855-
Files.copy(srcFile.toPath(), destFile.toPath(), copyOptions);
856+
Files.copy(srcPath, destFile.toPath(), copyOptions);
856857

857858
// On Windows, the last modified time is copied by default.
858859
if (preserveFileDate && !isSymLink && !setTimes(srcFile, destFile)) {

0 commit comments

Comments
 (0)