-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
More conservative write #8750
More conservative write #8750
Conversation
Still does not fix one of the root issues that there is no Filelock and that this method can be executed in parallel |
(outdated) Sure, this DOES NOT fix following issues: #6694, #8484, #6102, #4877, #8746. All of them are (currently) part of our next milestone v5.7: https://github.com/JabRef/jabref/milestone/26 This thing was one quick thought to implement following contract:
|
This reverts commit 048729b.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to take some inspiration by established libraries like https://github.com/npm/write-file-atomic or https://github.com/typicode/steno that implement similar secure writes, if you haven't done so. In particular, adding the pid and threadid, and invocation counter to the temporary file name looks like a good idea. Also having a thread lock-by-file is a good design choice in my opinion.
cleanup(); | ||
} | ||
} | ||
|
||
private void replaceOriginalFileByWrittenFile() throws IOException { | ||
// Move temporary file (replace original if it exists) | ||
// We implement the move as write into the original and delete the temporary one to keep file permissions etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then hard-exiting JabRef during a write operation may leave the file corrupt and kind of defeats the purpose of the atomic writer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: I'll create an ADR. - The intended implementation fixes #8887.
Refs #6688, because users don't want that directory to be cluttered. |
Another more general thing I just came across as I looked into this saving issues again:
|
# Conflicts: # build.gradle # src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java
src/test/java/org/jabref/logic/exporter/AtomicFileWriterTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/exporter/AtomicFileWriterTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/exporter/AtomicFileOutputStreamTest.java
Outdated
Show resolved
Hide resolved
# Conflicts: # CHANGELOG.md
src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java
Outdated
Show resolved
Hide resolved
… use line ending of library
src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java
Outdated
Show resolved
Hide resolved
# Conflicts: # src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Additionally - FileUtil vs. FileHelper comments Co-authored-by: Christoph <[email protected]> Co-authored-by: Carl Christian Snethlage <[email protected]>
Co-authored-by: Christoph <[email protected]> Co-authored-by: Carl Christian Snethlage <[email protected]>
Co-authored-by: Christoph <[email protected]> Co-authored-by: Carl Christian Snethlage <[email protected]>
Co-authored-by: Carl Christian Snethlage <[email protected]>
src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
Outdated
Show resolved
Hide resolved
I did a bit of research how other (code) editors are handling this and was a bit surprised that vscode for example uses a simple write (not an atomic write). However, there are quite a few issues in the vscode repo about lost or corrupt files, see microsoft/vscode#98063 and linked issues. Other data points: visual studio uses atomic writer, sublime text has an option to toggle between them. While going through vscode's code, I found a few really nice implementations of things that JabRef is struggling with. They might be handy to be used as reference. In general, the vscode is very readable and well-structured; so worth looking at.
|
# Conflicts: # src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java # src/main/java/org/jabref/logic/exporter/AtomicFileOutputStream.java # src/main/java/org/jabref/logic/util/BackupFileType.java # src/main/java/org/jabref/logic/util/io/FileUtil.java # src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
|
||
import org.jabref.logic.util.BackupFileType; | ||
import org.jabref.logic.util.io.BackupFileUtil; | ||
import org.jabref.logic.util.io.FileUtil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - org.jabref.logic.util.io.FileUtil.
We fixed the AtomicFileOutputStream in summer. The discussions at #8750 (comment) show that we should re-iterate on the idea again. - Especially #7718 should be regarded. We close this PR and need to go back. The ADR https://github.com/JabRef/jabref/pull/8750/files#diff-123ad108d1738a32004ec352c9156e0088de245e0cb840687b658725c40bbf96 can still from a good basis for capturing the implementation decisions. |
Refs #8746
This introduces a feature of our
AtomicFileWriter
to not "commit" changes if an error happened during write.I currently don't know how to test. Maybe simulating a small virtual hard disk not having enough space for writing?
should fix:
open things:
does not fix:
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)