]> source.dussan.org Git - poi.git/commitdiff
bug 57200,59788: be more specific why a temporary directory could not be created
authorJaven O'Neal <onealj@apache.org>
Wed, 21 Sep 2016 03:19:31 +0000 (03:19 +0000)
committerJaven O'Neal <onealj@apache.org>
Wed, 21 Sep 2016 03:19:31 +0000 (03:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1761667 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java

index ef9e8443a4aa43bdd05f09410ce232f216a7d0d3..6f44752873f0c975d2e1917cc9ab516e2e0ff2d4 100644 (file)
@@ -83,15 +83,22 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
     }
     
     /**
-     * Attempt to create a directory
+     * Attempt to create a directory, including any necessary parent directories.
+     * Does nothing if directory already exists.
      *
-     * @param directory
-     * @throws IOException
+     * @param directory  the directory to create
+     * @throws IOException if unable to create temporary directory or it is not a directory
      */
     private void createTempDirectory(File directory) throws IOException {
-        if (!(directory.exists() || directory.mkdirs()) || !directory.isDirectory()) {
+        // create directory if it doesn't exist
+        final boolean dirExists = (directory.exists() || directory.mkdirs());
+        
+        if (!dirExists) {
             throw new IOException("Could not create temporary directory '" + directory + "'");
         }
+        else if (!directory.isDirectory()) {
+            throw new IOException("Could not create temporary directory. '" + directory + "' exists but is not a directory.");
+        }
     }
     
     @Override