[
https://issues.apache.org/jira/browse/IO-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17801573#comment-17801573
]
Elliotte Rusty Harold commented on IO-807:
------------------------------------------
So on further investigation I think the broken symlink is not the root of the
problem. Imagine we have this layout where /home/bar/linkfile points to
/tmp/foo.txt:
/tmp/foo.txt contains the bytes for "Hello"
/home/bar/linkfile --> /tmp/foo.txt
Now let's copy /home/bar to /home/baz using FileUtils.copyDirectory. What we
end up with is
/home/baz/linkfile contains the bytes for "Hello"
That is, there is now a file in /home/baz named "linkfile" that contains the
same bytes as /tmp/foo.txt. Note that this file is *not* a symbolic link.
Rather the copy operation resolves all symbolic links though bit retains the
names of the symbolic links.
This behavior strikes me as surprising. As near as I can see it's neither
tested nor documented. It's simply a side effect of how copyDirectory was
implemented.
What I think should happen is that copyDirectory should copy links as links,
rather than turning them into non-link files.
This is even more obvious for moveDirectory, though I haven't yet tested that
case.
> FileUtils.requireExists does not take into account soft links
> -------------------------------------------------------------
>
> Key: IO-807
> URL: https://issues.apache.org/jira/browse/IO-807
> Project: Commons IO
> Issue Type: Improvement
> Components: Utilities
> Affects Versions: 2.13.0
> Reporter: Jordi Sola
> Priority: Major
>
> The current sources for `FileUtils.requireExists` and `FileUtils.
> requireExistsChecked` just check for the existence of the file, delegating to
> the `File.exists` method:
> {code:java}
> Objects.requireNonNull(file, fileParamName);
> if (!file.exists()) {
> throw ...
> }
> return file;{code}
> The default `file` implementation returns `false` if the file is a broken
> symbolic link (that is, a symbolic link pointing to an non-existing file).
> While this implementation can be seen as correct most of the time, sometimes
> we need to avoid following the link, and evaluate the existence of the link
> itself.
> For example, when using `FileUtils#copyDirectory` with the
> `LinkOption.NOFOLLOW_LINKS` option, it is expected that broken links are
> copied (see JavaDocs for `java.nio.file.Files#copy`). Nonetheless, as
> `FileUtils#requireFileIfExists` returns `false`, the file is just ignored.
>
> One possible approach is relying in `java.nio.file.Files#isSymbolicLink` when
> `LinkOption.NOFOLLOW_LINKS` options is provided.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)