[ https://issues.apache.org/jira/browse/IO-798?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael Osipov updated IO-798: ------------------------------ Summary: DeferredFileOutputStream throws exception when system temp dir is a symlink (was: DeferredFileOutputStream throws exception when system temp folder is a symlink) > DeferredFileOutputStream throws exception when system temp dir is a symlink > --------------------------------------------------------------------------- > > Key: IO-798 > URL: https://issues.apache.org/jira/browse/IO-798 > Project: Commons IO > Issue Type: Bug > Components: Streams/Writers > Affects Versions: 2.12.0 > Reporter: Shai Shapira > Priority: Minor > > We have some code that creates an org.apache.commons.fileupload.FileItem and > writes to its OutputStream. This worked well until commons-io version 12 came > out, then started to throw a FileAlreadyExistsException. After some > investigation, this is what seems to be happening: > Our FileItem (created by a DiskFileItemFactory) uses a > DeferredFileOutputStream as its output stream. DeferredFileOutputStream uses > the system temp folder to save the file if it gets too big. When saving the > file, it wants to create any parent folders if they don't already exist. > The problem is, the logic for creating the parent folders seems to have been > rewritten for version 2.12.0, and now calls: > PathUtils.createParentDirectories({color:#9876aa}outputPath{color}){color:#cc7832}; > _{color:#172b4d}(DeferredFileOutputStream.java, line 333){color}_{color} > {color:#172b4d}This method, by default, uses a parameter telling it not to > follow links. On our servers, the temp folder is, unfortunately, a link. So > the method looks at the folder in the file path, and sees the link. Since it > does not follow links, it just sees that something other than a directory > exists in this path, and throws an Exception. > {color} > The code looks something like this: > FileItemFactory fileFact = {color:#cc7832}new > {color}DiskFileItemFactory(){color:#cc7832}; > {color}FileItem file = fileFact.createItem(fieldName{color:#cc7832}, > {color}contentType{color:#cc7832}, {color}{color:#cc7832}false, > {color}fileName){color:#cc7832}; > {color}{color:#cc7832}try {color}(OutputStream out = file.getOutputStream()) { > {color:#cc7832}{color:#172b4d}<code that writes into{color} > {_}out{_}{color:#172b4d}>{color} > {color}} > > And the stack trace: > java.nio.file.FileAlreadyExistsException: /usr/local/apache-tomcat-base/temp > 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 -- This message was sent by Atlassian Jira (v8.20.10#820010)