-
-
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
AtomicFileOutputStream does not overwrite file if exception occurred during write #9067
Conversation
… on issues during saving
If you have now autosave and normal saving at the same time you will get an exception due to the File lock because of this condition:
|
Please also note:
|
Co-authored-by: Christoph <siedlerkiller@gmail.com> Co-authored-by: ThiloteE <73715071+ThiloteE@users.noreply.github.com>
…cation of save actions Co-authored-by: Christoph <siedlerkiller@gmail.com> Co-authored-by: ThiloteE <73715071+ThiloteE@users.noreply.github.com>
/** | ||
* 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 | ||
*/ | ||
public AtomicFileOutputStream(Path path, boolean keepBackup) throws IOException { | ||
super(Files.newOutputStream(getPathOfTemporaryFile(path))); | ||
// Files.newOutputStream(getPathOfTemporaryFile(path)) leads to a "sun.nio.ch.ChannelOutputStream", which does not offer "lock" |
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.
Useless comment
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.
No, the comment is indeed useful because it makes clear why we chose the old io and not the nio one
This refines the
AtomicFileOutputStream
to not overwrite a file if an exception occurred during write. This is done by introducing a flagerrorDuringWrite
and handling that in theclose()
method.CHANGELOG.md
described in a way that is understandable for the average user (if applicable)