From 133958836d6ae243495c16035da6295ab28aafb2 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Thu, 16 Mar 2023 22:39:43 +0100 Subject: [PATCH 1/2] Always delete the `.sav` file upon successful write --- CHANGELOG.md | 1 + .../org/jabref/logic/exporter/AtomicFileOutputStream.java | 7 ++++--- .../java/org/jabref/logic/exporter/SavePreferences.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f1277ee13f..55ec4823ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - 'Get full text' now also checks the file url. [#568](https://github.com/koppor/jabref/issues/568) - We refined the 'main directory not found' error message. [#9625](https://github.com/JabRef/jabref/pull/9625) - We modified the `Add Group` dialog to use the most recently selected group hierarchical context [#9141](https://github.com/JabRef/jabref/issues/9141) +- To avoid cluttering of the directory, We always delete the `.sav` file upon successful write. diff --git a/src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java b/src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java index 5694d79b803..58f98365592 100644 --- a/src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java +++ b/src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java @@ -62,6 +62,7 @@ public class AtomicFileOutputStream extends FilterOutputStream { private final Path temporaryFile; private final FileLock temporaryFileLock; + /** * A backup of the target file (if it exists), created when the stream is closed */ @@ -75,7 +76,7 @@ public class AtomicFileOutputStream extends FilterOutputStream { * Creates a new output stream to write to or replace the file at the specified path. * * @param path the path of the file to write to or replace - * @param keepBackup whether to keep the backup file after a successful write process + * @param keepBackup whether to keep the backup file (.sav) after a successful write process */ public AtomicFileOutputStream(Path path, boolean keepBackup) throws IOException { // Files.newOutputStream(getPathOfTemporaryFile(path)) leads to a "sun.nio.ch.ChannelOutputStream", which does not offer "lock" @@ -84,7 +85,7 @@ public AtomicFileOutputStream(Path path, boolean keepBackup) throws IOException /** * Creates a new output stream to write to or replace the file at the specified path. - * The backup file is deleted when write was successful. + * The backup file (.sav) is deleted when write was successful. * * @param path the path of the file to write to or replace */ @@ -238,7 +239,7 @@ public void close() throws IOException { } if (!keepBackup) { - // Remove backup file + // Remove backup file for saving Files.deleteIfExists(backupFile); } } finally { diff --git a/src/main/java/org/jabref/logic/exporter/SavePreferences.java b/src/main/java/org/jabref/logic/exporter/SavePreferences.java index 1165d3338c9..a566c0c3449 100644 --- a/src/main/java/org/jabref/logic/exporter/SavePreferences.java +++ b/src/main/java/org/jabref/logic/exporter/SavePreferences.java @@ -49,7 +49,7 @@ public SavePreferences(Boolean saveInOriginalOrder, this(saveInOriginalOrder, saveOrder, - true, + false, saveType, takeMetadataSaveOrderInAccount, reformatFile, From 2f11ed9fa67c175da270a77ddcfa46ff8ac1de15 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 20 Mar 2023 23:01:06 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 313d6841bbb..7d99f5957d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - Backups of libraries are not stored per JabRef version, but collected together. - We modified the `Add Group` dialog to use the most recently selected group hierarchical context [#9141](https://github.com/JabRef/jabref/issues/9141) - We improved the Medline importer to correctly import ISO dates for `revised`. [#9536](https://github.com/JabRef/jabref/issues/9536) -- To avoid cluttering of the directory, We always delete the `.sav` file upon successful write. +- To avoid cluttering of the directory, We always delete the `.sav` file upon successful write. [#9675](https://github.com/JabRef/jabref/pull/9675)