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

Regression in FileUtils.touch - no longer creates parent directories

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.12.0
    • 2.13.0
    • Utilities
    • None

    Description

      The behavior of this (and possibly other logic) seems to have regressed in 2.12.0 compared to 2.11.0. As documented in the Javadoc "Also, as from v1.3 this method creates parent directories if they do not exist." (see here) but this no longer works, instead it uses PathUtils.touch which does not have the capability of creating the parent dirs.

      e.g

          @Test
          public void doTouch() throws Exception {
              FileUtils.touch(new File("doesnt-exist", "touchme.txt"));
          }

      doesnt-exist/touchme.txt
      java.nio.file.NoSuchFileException: doesnt-exist/touchme.txt
          at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
          at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
          at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
          at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
          at java.base/java.nio.file.Files.newByteChannel(Files.java:380)
          at java.base/java.nio.file.Files.createFile(Files.java:658)
          at org.apache.commons.io.file.PathUtils.touch(PathUtils.java:1613)
          at org.apache.commons.io.FileUtils.touch(FileUtils.java:3090)

       

       

      Appears to have regressed in https://github.com/apache/commons-io/commit/fd7c8182d2117d01f43ccc9fe939105f834ba672 - PathUtils relies on java.nio.Files.createFile which explicitly does not have ability to create parent directories.

      Attachments

        Activity

          People

            ggregory Gary D. Gregory
            chadwilson Chad Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: