From a0423e6189133e3601879969f38c6f8699ac1fd0 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Mon, 8 Jul 2024 14:39:07 +0200 Subject: [PATCH] CSSTUDIO-2460 Add a finalizer that deletes the temporary file containing an attachment when the corresponding 'fileAttachment' is garbage collected. --- .../logbook/olog/ui/SingleLogEntryDisplayController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java index 2ef0956433..ba6960d68f 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java @@ -188,7 +188,14 @@ private void fetchAttachments() { Collection attachments = logEntry.getAttachments().stream() .filter((attachment) -> attachment.getName() != null && !attachment.getName().isEmpty()) .map((attachment) -> { - OlogAttachment fileAttachment = new OlogAttachment(); + OlogAttachment fileAttachment = new OlogAttachment() { + @Override + protected void finalize() { + if (getFile() != null && getFile().exists()) { + getFile().delete(); + } + } + }; fileAttachment.setContentType(attachment.getContentType()); fileAttachment.setThumbnail(false); fileAttachment.setFileName(attachment.getName());