Author: fanningpj
Date: Fri Sep 13 11:09:21 2024
New Revision: 1920610

URL: http://svn.apache.org/viewvc?rev=1920610&view=rev
Log:
[bug-69323] DefaultTempFileCreationStrategy should worry about OS deleting the 
temp dir. Thanks to Palle Girgensohn. This closes #691

Modified:
    
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java?rev=1920610&r1=1920609&r2=1920610&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
 (original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
 Fri Sep 13 11:09:21 2024
@@ -73,9 +73,13 @@ public class DefaultTempFileCreationStra
         this.dir = dir;
     }
 
-    private void createPOIFilesDirectory() throws IOException {
-        // Create our temp dir only once by double-checked locking
-        // The directory is not deleted, even if it was created by this 
TempFileCreationStrategy
+    // Create our temp dir only once by double-checked locking
+    // The directory is not deleted, even if it was created by this 
TempFileCreationStrategy
+    private void createPOIFilesDirectoryIfNecessary() throws IOException {
+        // First make sure we recreate the directory if it was not somehow 
removed by a third party
+        if (dir != null && !dir.exists()) {
+            dir = null;
+        }
         if (dir == null) {
             final String tmpDir = System.getProperty(JAVA_IO_TMPDIR);
             if (tmpDir == null) {
@@ -104,7 +108,7 @@ public class DefaultTempFileCreationStra
     @Override
     public File createTempFile(String prefix, String suffix) throws 
IOException {
         // Identify and create our temp dir, if needed
-        createPOIFilesDirectory();
+        createPOIFilesDirectoryIfNecessary();
 
         // Generate a unique new filename
         File newFile = Files.createTempFile(dir.toPath(), prefix, 
suffix).toFile();
@@ -122,7 +126,7 @@ public class DefaultTempFileCreationStra
     @Override
     public File createTempDirectory(String prefix) throws IOException {
         // Identify and create our temp dir, if needed
-        createPOIFilesDirectory();
+        createPOIFilesDirectoryIfNecessary();
 
         // Generate a unique new filename
         File newDirectory = Files.createTempDirectory(dir.toPath(), 
prefix).toFile();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to