Skip to content

Commit 02833b8

Browse files
committed
BroadleafCommerce#1452 - When creating a temporary file work area, include the thread id in the directory path. When removing the directories in the temporary path, do not fail if a directory is unable to be deleted.
Changed loop index when deleting directories from 1 to 0 since we now have 1 additional directory (the thread id directory) to delete.
1 parent f401081 commit 02833b8

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

common/src/main/java/org/broadleafcommerce/common/file/service/BroadleafFileServiceImpl.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import java.io.BufferedInputStream;
4040
import java.io.File;
41-
import java.io.IOException;
4241
import java.io.InputStream;
4342
import java.util.ArrayList;
4443
import java.util.Collection;
@@ -124,20 +123,15 @@ public FileWorkArea initializeWorkArea() {
124123
@Override
125124
public void closeWorkArea(FileWorkArea fwArea) {
126125
File tempDirectory = new File(fwArea.getFilePathLocation());
127-
try {
128-
if (tempDirectory.exists()) {
129-
FileUtils.deleteDirectory(tempDirectory);
130-
}
126+
if (tempDirectory.exists()) {
127+
FileUtils.deleteQuietly(tempDirectory);
128+
}
131129

132-
for (int i = 1; i < maxGeneratedDirectoryDepth; i++) {
133-
tempDirectory = tempDirectory.getParentFile();
134-
if (tempDirectory.list().length == 0 && tempDirectory.exists()) {
135-
FileUtils.deleteDirectory(tempDirectory);
136-
}
130+
for (int i = 0; i < maxGeneratedDirectoryDepth; i++) {
131+
tempDirectory = tempDirectory.getParentFile();
132+
if (!tempDirectory.delete()) {
133+
break;
137134
}
138-
139-
} catch (IOException ioe) {
140-
throw new FileServiceException("Unable to delete temporary working directory for " + tempDirectory, ioe);
141135
}
142136
}
143137

@@ -358,14 +352,19 @@ protected String getTempDirectory(String baseDirectory) {
358352
for (int i = 0; i < maxGeneratedDirectoryDepth; i++) {
359353
if (i == 4) {
360354
LOG.warn("Property asset.server.max.generated.file.system.directories set to high, currently set to " +
361-
maxGeneratedDirectoryDepth);
355+
maxGeneratedDirectoryDepth + " ignoring and only creating 4 levels.");
362356
break;
363357
}
364358
// check next int value
365359
int num = random.nextInt(256);
366360
baseDirectory = FilenameUtils.concat(baseDirectory, Integer.toHexString(num));
367361
}
368-
return baseDirectory;
362+
363+
return FilenameUtils.concat(baseDirectory, buildThreadIdString());
364+
}
365+
366+
protected String buildThreadIdString() {
367+
return Long.toHexString(Thread.currentThread().getId());
369368
}
370369

371370
/**

0 commit comments

Comments
 (0)