rnote icon indicating copy to clipboard operation
rnote copied to clipboard

fix: Write in a temp file before replacing the original file, fixes #903

Open Midou36O opened this issue 10 months ago • 6 comments

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

Midou36O avatar Feb 25 '25 10:02 Midou36O

This also fixes #1128

Doublonmousse avatar Mar 16 '25 09:03 Doublonmousse

( Mini bump in case it got missed, or needs changes :p )

Midou36O avatar Apr 20 '25 22:04 Midou36O

This looks good! Initially, something similar was explored in #1177, but as this other PR touches on the file format (and we don't want to change it every morning) it'll take time before this other PR is merged.

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)

Doublonmousse avatar Apr 21 '25 11:04 Doublonmousse

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

  • open rnote
  • edit the document
  • save to a new document
  • wait for the save to finish/popups to disappear (success!)
  • CTRL + S again
  • "Opened file was removed" and rnote treats the opened tab as a yet-to-be saved.

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) https://github.com/flxzt/rnote/blob/8db8dc1460434366f100cc6d1063aeb04b00fa0b/crates/rnote-ui/src/canvas/mod.rs#L1012-L1015 (and a little further down here https://github.com/flxzt/rnote/blob/8db8dc1460434366f100cc6d1063aeb04b00fa0b/crates/rnote-ui/src/canvas/mod.rs#L1074-L1077)

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

Doublonmousse avatar Apr 21 '25 13:04 Doublonmousse

You might be interested in this:

  • https://github.com/flxzt/rnote/pull/1177/files#diff-e1e60757edbac1f4d8741ee8fa9d64ae21ec07d180c4b01b455e854f29782fe2
  • https://github.com/flxzt/rnote/pull/1177/files#diff-69e14b6632502e3ecc34bc99cab25aebed4717bb0b288df3f5f8fb96808827a4

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)));

anesthetice avatar May 01 '25 14:05 anesthetice

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.

Midou36O avatar May 02 '25 15:05 Midou36O