aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-05-08 17:24:41 +0000
committerPJ Fanning <fanningpj@apache.org>2024-05-08 17:24:41 +0000
commitefce9ba9304a93da39d83a0bde2b403fd7f0640e (patch)
treee42d549f9d743bcbcc66aa1787943a7ad06ead2f /poi
parentc960ee60709a4059796a13eec3b383ea4363f4fc (diff)
downloadpoi-efce9ba9304a93da39d83a0bde2b403fd7f0640e.tar.gz
poi-efce9ba9304a93da39d83a0bde2b403fd7f0640e.zip
add back check for if dir already exists
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917583 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java18
1 files changed, 13 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 b4105583a2..d469c4744d 100644
--- a/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
+++ b/poi/src/main/java/org/apache/poi/util/DefaultTempFileCreationStrategy.java
@@ -77,15 +77,23 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
// Create our temp dir only once by double-checked locking
// The directory is not deleted, even if it was created by this TempFileCreationStrategy
if (dir == null) {
+ final String tmpDir = System.getProperty(JAVA_IO_TMPDIR);
+ if (tmpDir == null) {
+ throw new IOException("System's temporary directory not defined - set the -D" + JAVA_IO_TMPDIR + " jvm property!");
+ }
dirLock.lock();
try {
if (dir == null) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR);
- if (tmpDir == null) {
- throw new IOException("System's temporary directory not defined - set the -D" + JAVA_IO_TMPDIR + " jvm property!");
- }
Path dirPath = Paths.get(tmpDir, POIFILES);
- dir = Files.createDirectories(dirPath).toFile();
+ File fileDir = dirPath.toFile();
+ if (fileDir.exists()) {
+ if (!fileDir.isDirectory()) {
+ throw new IOException("Could not create temporary directory. '" + fileDir + "' exists but is not a directory.");
+ }
+ dir = fileDir;
+ } else {
+ dir = Files.createDirectories(dirPath).toFile();
+ }
}
} finally {
dirLock.unlock();