Skip to content

Commit

Permalink
[bug-69323] DefaultTempFileCreationStrategy should worry about OS del…
Browse files Browse the repository at this point in the history
…eting 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
  • Loading branch information
pjfanning committed Sep 13, 2024
1 parent 5b404eb commit 5a977d1
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ public DefaultTempFileCreationStrategy(File dir) {
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) {
Expand Down Expand Up @@ -104,7 +108,7 @@ private void createPOIFilesDirectory() throws IOException {
@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();
Expand All @@ -122,7 +126,7 @@ public File createTempFile(String prefix, String suffix) throws IOException {
@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();
Expand Down

0 comments on commit 5a977d1

Please sign in to comment.