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 1 commit
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 @@ -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.



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