Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-807

FileUtils.requireExists does not take into account soft links

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.13.0
    • 2.16.0
    • Utilities
    • None

    Description

      The current sources for `FileUtils.requireExists` and `FileUtils.
      requireExistsChecked` just check for the existence of the file, delegating to the `File.exists` method:

              Objects.requireNonNull(file, fileParamName);
              if (!file.exists()) {
                  throw ...
              }
              return file;

      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.
       

      Attachments

        Activity

          People

            Unassigned Unassigned
            someth2say Jordi Sola
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: