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

Always delete the .sav file upon successful write #9675

Merged
merged 5 commits into from
Mar 27, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- `log.txt` now contains debug messages. Debugging needs to be enabled explicitly. [#9678](https://github.com/JabRef/jabref/pull/9678)
- `log.txt` does not contain entries for non-found files during PDF indexing. [#9678](https://github.com/JabRef/jabref/pull/9678)
- 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. [#9675](https://github.com/JabRef/jabref/pull/9675)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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"
Expand All @@ -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
*/
Expand Down Expand Up @@ -238,7 +239,7 @@ public void close() throws IOException {
}

if (!keepBackup) {
// Remove backup file
// Remove backup file for saving
Files.deleteIfExists(backupFile);
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SavePreferences(Boolean saveInOriginalOrder,

this(saveInOriginalOrder,
saveOrder,
true,
false,
saveType,
takeMetadataSaveOrderInAccount,
reformatFile,
Expand Down