Skip to content

Commit

Permalink
#IQSS/3818 Delete temp thumbnail files
Browse files Browse the repository at this point in the history
  • Loading branch information
haarli committed Jun 14, 2023
1 parent fd190a3 commit 9c809c4
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ private static boolean generatePDFThumbnail(StorageIO<DataFile> storageIO, int s
// will run the ImageMagick on it, and will save its output in another temp
// file, and will save it as an "auxiliary" file via the driver.
boolean tempFilesRequired = false;
File tempFile = null;

try {
Path pdfFilePath = storageIO.getFileSystemPath();
Expand Down Expand Up @@ -222,7 +223,7 @@ private static boolean generatePDFThumbnail(StorageIO<DataFile> storageIO, int s
return false;
}

File tempFile;

FileChannel tempFileChannel = null;
try {
tempFile = File.createTempFile("tempFileToRescale", ".tmp");
Expand Down Expand Up @@ -254,10 +255,14 @@ private static boolean generatePDFThumbnail(StorageIO<DataFile> storageIO, int s
try {
logger.fine("attempting to save generated pdf thumbnail, as AUX file " + THUMBNAIL_SUFFIX + size);
storageIO.savePathAsAux(Paths.get(imageThumbFileName), THUMBNAIL_SUFFIX + size);

} catch (IOException ioex) {
logger.warning("failed to save generated pdf thumbnail, as AUX file " + THUMBNAIL_SUFFIX + size + "!");
return false;
}
finally {
tempFile.delete();
}
}

return true;
Expand Down Expand Up @@ -353,12 +358,18 @@ private static boolean generateImageThumbnailFromInputStream(StorageIO<DataFile>

if (tempFileRequired) {
storageIO.savePathAsAux(Paths.get(tempFile.getAbsolutePath()), THUMBNAIL_SUFFIX + size);

}

} catch (Exception ioex) {
logger.warning("Failed to rescale and/or save the image: " + ioex.getMessage());
return false;
}
finally {
if(tempFileRequired) {
tempFile.delete();
}
}

return true;

Expand Down

0 comments on commit 9c809c4

Please sign in to comment.