Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3818 Delete temporary thumbnail files #9637

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 @@ 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 {
try {
tempFile.delete();
}
catch (Exception e) {}
}
}

return true;
Expand Down Expand Up @@ -353,12 +361,21 @@ 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) {
try {
tempFile.delete();
}
catch (Exception e) {}
}
}

return true;

Expand Down