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

FileAlreadyExistsException in PathUtils.createParentDirectories(Path, LinkOption, FileAttribute<?>...)

    XMLWordPrintableJSON

Details

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

    Description

      Switching from 2.11.0 to 2.12.0 causes the following exception in commons-fileupload (1.5):
       

      Caused by: java.nio.file.FileAlreadyExistsException: /home/A/B/C
              at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:94)
              at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
              at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
              at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:389)
              at java.base/java.nio.file.Files.createDirectory(Files.java:690)
              at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:797)
              at java.base/java.nio.file.Files.createDirectories(Files.java:743)
              at org.apache.commons.io.file.PathUtils.createParentDirectories(PathUtils.java:383)
              at org.apache.commons.io.file.PathUtils.createParentDirectories(PathUtils.java:367)
              at org.apache.commons.io.output.DeferredFileOutputStream.thresholdReached(DeferredFileOutputStream.java:333)
              at org.apache.commons.io.output.ThresholdingOutputStream.checkThreshold(ThresholdingOutputStream.java:105)
              at org.apache.commons.io.output.ThresholdingOutputStream.write(ThresholdingOutputStream.java:231)
              at org.apache.commons.fileupload.util.Streams.copy(Streams.java:105)
              at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:376) 

       
      where B and C are symbolic links.
       
      In particular, DeferredFileOutputStream#thresholdReached has been modified from:
       
       

      protected void thresholdReached() throws IOException {
          if (prefix != null) {
              outputFile = File.createTempFile(prefix, suffix, directory);
          }
          FileUtils.forceMkdirParent(outputFile);
          final OutputStream fos = Files.newOutputStream(outputFile.toPath());
      
      	[...]
      }
      

        
      to:
       

      protected void thresholdReached() throws IOException {
          if (prefix != null) {
              outputPath = Files.createTempFile(directory, prefix, suffix);
          }
          PathUtils.createParentDirectories(outputPath);
          final OutputStream fos = Files.newOutputStream(outputPath);
          
          [...]
      } 

      Attachments

        1. FileAlreadyExistsTest.java
          17 kB
          Giacomo Boccardo

        Activity

          People

            ggregory Gary D. Gregory
            jhack Giacomo Boccardo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: