diff options
author | PJ Fanning <fanningpj@apache.org> | 2024-09-13 11:09:21 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2024-09-13 11:09:21 +0000 |
commit | 5a977d1a7b70714e1efa1d780478394f63dc112a (patch) | |
tree | 37b86df950f3fbf3f0ef79320fd059884a98c5c7 | |
parent | 5b404ebc6b9703d693dbac98c0939d61856a2dc0 (diff) | |
download | poi-5a977d1a7b70714e1efa1d780478394f63dc112a.tar.gz poi-5a977d1a7b70714e1efa1d780478394f63dc112a.zip |
[bug-69323] DefaultTempFileCreationStrategy should worry about OS deleting the temp dir. Thanks to Palle Girgensohn. This closes #691
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1920610 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java index d469c4744d..588c027b61 100644 --- a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java +++ b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java @@ -73,9 +73,13 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy 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 DefaultTempFileCreationStrategy implements TempFileCreationStrategy @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 DefaultTempFileCreationStrategy implements TempFileCreationStrategy @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(); |