-
-
Notifications
You must be signed in to change notification settings - Fork 356
fix: Write in a temp file before replacing the original file, fixes #903 #1370
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
base: main
Are you sure you want to change the base?
Conversation
This also fixes #1128 |
( Mini bump in case it got missed, or needs changes :p ) |
This looks good! So it makes sense to merge this PR as it fixes your issue now, knowing that this may be refactored further down the line when it comes time to merge #1177. The only concern is how this change affect the file watcher, so that we don't have a "file modified on disk" when saving and keep the protection of the window not closing until the file is actually saved #1096. (So some testing is in order to verify this isn't affected) |
I'm testing so see whether this works well with the file watcher and I'm encountering an issue. For now I'm doing the following
This is expected because the file watcher sees the file being removed when replacing the file and acts on it. It's actually the same thing for writing to the file (the file watcher sees the file being modified/written to) but its output is suppressed by doing self.set_output_file_expect_write(true); and preventing anything happening here (so that we don't see that the file is modified on disk when saving) rnote/crates/rnote-ui/src/canvas/mod.rs Lines 1012 to 1015 in 8db8dc1
(and a little further down here rnote/crates/rnote-ui/src/canvas/mod.rs Lines 1074 to 1077 in 8db8dc1
So you probably need to check what kind of events get sent in that enum when saving a file for the second time and suppress this additional event |
You might be interested in this:
But basically to get around the file watcher issue I just set the output file to the "new" one: self.set_output_file(Some(gio::File::for_path(&filepath))); |
Thanks, I just don't have time right to look into it right now but once I get back to it I'll try to replicate what you've done. |
I'm not experienced in rust but i thought saving in a temporary file would help avoid corrupting the original file if the save fails. Tested on my laptop and it does avoid corrupting the original file, which is the intended behavior.
This should fix #903