aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-common/src')
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/TempFileHelper.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/TempFileHelper.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/TempFileHelper.java
index 611d7a0b..03cd28f3 100644
--- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/TempFileHelper.java
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/TempFileHelper.java
@@ -27,6 +27,8 @@ public class TempFileHelper implements IProfileConstants {
private List<String> tmpFiles = new ArrayList<String>();
+ private boolean needsDeletion = false;
+
public TempFileHelper(ISettings settings) {
initializeMD();
@@ -37,9 +39,12 @@ public class TempFileHelper implements IProfileConstants {
// relatives tmp dir
myTmpDirFile = new File(settings.getWorkingDirectory() + File.separator + myTmpDir);
}
- tmpDir = myTmpDirFile.getAbsolutePath();
+ tmpDir = myTmpDirFile.getAbsolutePath() + File.separator;
} else {
- tmpDir = settings.getWorkingDirectory() + File.separator + TMP_DIR_DEFAULT_VALUE;
+ String uuidString = UUID.randomUUID().toString();
+ logger.debug("Generated UUID " + uuidString);
+ tmpDir = settings.getWorkingDirectory() + File.separator + TMP_DIR_DEFAULT_VALUE + File.separator + getHashedHexString(uuidString) + File.separator;
+ needsDeletion = true;
}
logger.info("TempDirHelper for TempDirectory: " + tmpDir);
@@ -66,6 +71,9 @@ public class TempFileHelper implements IProfileConstants {
try {
File tmpdir = new File(tmpDir);
tmpdir.mkdirs();
+ if(needsDeletion) {
+ tmpdir.deleteOnExit();
+ }
} catch (Throwable e) {
logger.error("Failed to create temporary directory: " + tmpDir, e);
}
@@ -101,7 +109,7 @@ public class TempFileHelper implements IProfileConstants {
public String getStaticFilename() {
String uuidString = UUID.randomUUID().toString();
logger.debug("Generated UUID " + uuidString);
- String tmpFilename = tmpFilePrefix + getHashedHexString(uuidString) + tmpFileSuffix;
+ String tmpFilename = tmpDir + getHashedHexString(uuidString) + tmpFileSuffix;
logger.info("Temporary filename " + tmpFilename);
tmpFiles.add(tmpFilename);
return tmpFilename;