Skip to content

Commit

Permalink
Merge pull request #3113 from ControlSystemStudio/fix_olog_attachments
Browse files Browse the repository at this point in the history
Fixing unnecessary creation of Olog temp files
  • Loading branch information
shroffk authored Aug 19, 2024
2 parents e5cb1b8 + 7e9205c commit 9d15306
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public OlogAttachment deserialize(JsonParser jp, DeserializationContext ctxt)
String fileMetadataDescription = node.get("fileMetadataDescription").asText();
OlogAttachment a = new OlogAttachment();
a.setFileName(filename);
a.setId(id);
a.setContentType(fileMetadataDescription);
return a;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,21 @@ protected void finalize() {
fileAttachment.setContentType(attachment.getContentType());
fileAttachment.setThumbnail(false);
fileAttachment.setFileName(attachment.getName());
// A bit of a hack here. The idea is to create a temporary file with a known name,
// i.e. without the random file name part.
// Files.createdTempFile does not support it, so a bit of workaround is needed.
try {
Path temp = Files.createTempFile("phoebus", attachment.getName());
Files.copy(logClient.getAttachment(logEntry.getId(), attachment.getName()), temp, StandardCopyOption.REPLACE_EXISTING);
fileAttachment.setFile(temp.toFile());
temp.toFile().deleteOnExit();
// This creates a temp file with a random part
Path random = Files.createTempFile(attachment.getId(), attachment.getName());
// This does NOT create a file
Path nonRandom = random.resolveSibling(attachment.getId());
if(!Files.exists(nonRandom.toAbsolutePath())){
// Moves the temp file with random part to file with non-random part.
nonRandom = Files.move(random, nonRandom);
Files.copy(logClient.getAttachment(logEntry.getId(), attachment.getName()), nonRandom, StandardCopyOption.REPLACE_EXISTING);
fileAttachment.setFile(nonRandom.toFile());
nonRandom.toFile().deleteOnExit();
}
} catch (LogbookException | IOException e) {
Logger.getLogger(SingleLogEntryDisplayController.class.getName())
.log(Level.WARNING, "Failed to retrieve attachment " + fileAttachment.getFileName(), e);
Expand Down

0 comments on commit 9d15306

Please sign in to comment.