[ 
https://issues.apache.org/jira/browse/IO-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17801816#comment-17801816
 ] 

Elliotte Rusty Harold edited comment on IO-807 at 1/4/24 2:27 PM:
------------------------------------------------------------------

After non-exhaustive testing in bash on my Mac, the behavior you're describing 
is for hard links. However for symbolic links, the link is copied. The data is 
not copied. I suspect that should be our default in the absence of copy options 
that say otherwise. That is, when copying a symbolic link to a new location, 
create a new symbolic link that points to the same path the original symbolic 
link pointed to.

And even for hard links, not quite because hard links can share the same inode 
and fiels copied byte per byte don't. We can use Files.createLink to create a 
hard link and Files.createSymbolicLink to create a soft link as needed. 


was (Author: elharo):
After non-exhaustive testing in bash on my Mac, the behavior you're describing 
is for hard links. However for symbolic links, the link is copied. The data is 
not copied. I suspect that should be our default in the absence of copy options 
that say otherwise. That is, when copying a symbolic link to a new location, 
create a new symbolic link that points to the same path the original symbolic 
link pointed to.

And even for hard links, not quite because hard links can share the same inode 
and fiels copied byte per byte don't.

> 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)

Reply via email to