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

cleanup temporary files, use prefix "jabref-" #7811

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -25,9 +25,12 @@ public static JournalAbbreviationRepository loadRepository(JournalAbbreviationPr
JournalAbbreviationRepository repository;
// Initialize with built-in list
try {
Path tempJournalList = Files.createTempDirectory("journal").resolve("journalList.mv");
Path tempDir = Files.createTempDirectory("jabref-journal");
Path tempJournalList = tempDir.resolve("journalList.mv");
Files.copy(JournalAbbreviationRepository.class.getResourceAsStream("/journals/journalList.mv"), tempJournalList);
repository = new JournalAbbreviationRepository(tempJournalList);
tempDir.toFile().deleteOnExit();
tempJournalList.toFile().deleteOnExit();
} catch (IOException e) {
LOGGER.error("Error while copying journal list", e);
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/logic/net/URLDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,12 @@ public Path toTemporaryFile() throws IOException {

// Take everything after the last '/' as name + extension
String fileNameWithExtension = sourcePath.substring(sourcePath.lastIndexOf('/') + 1);
String fileName = FileUtil.getBaseName(fileNameWithExtension);
String fileName = "jabref-" + FileUtil.getBaseName(fileNameWithExtension);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to think long about this. Since its a temporary file anyway, the filename doesn't matter. Thus, good to go!

String extension = "." + FileHelper.getFileExtension(fileNameWithExtension).orElse("tmp");

// Create temporary file and download to it
Path file = Files.createTempFile(fileName, extension);
file.toFile().deleteOnExit();
toFile(file);

return file;
Expand Down