flxzt / rnote

Sketch and take handwritten notes.
https://rnote.flxzt.net
GNU General Public License v3.0
6.42k stars 215 forks source link

Closing app while saving is in progress is not inhibited, leading to file corruption #1096

Closed devxbasit closed 2 days ago

devxbasit commented 1 month ago

Describe the bug I get the below error when I try to open a file. I'm not sure, but yesterday after pressing the [CTRL+ S] to save the file, I quickly closed the app. Any way to recover the file back it contains my study notes. Thank you for this awesome app, it is so helpful.

image

To Reproduce
Steps to reproduce the behavior:

  1. open the file

Expected behavior

Console Output
Run the app in the terminal with flatpak --env=RUST_LOG=rnote=debug --env=RUST_BACKTRACE=1 run com.github.flxzt.rnote and post the output.

ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libgtk3-nocsd.so.0' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored. 2024-05-13T17:35:15.035678Z DEBUG rnote: .. tracing subscriber initialized. 2024-05-13T17:35:19.422295Z ERROR rnote::appwindow: Opening file with dialogs failed, Err: loading RnoteFile from bytes failed.

Caused by: 0: decompressing bytes failed. 1: unexpected end of file

Stack backtrace: 0: 1: 2: 3: 4: 5: 6: 7: 8: __clone 2024-05-13T17:35:19.425417Z ERROR rnote::overlays: Opening file failed

Screenshots

Desktop (please complete the following information):
Xubuntu image

Additional context

flxzt commented 1 month ago

Unfortunately it reads like the file hasn't finished saving when you closed the app.

We should definitely fix this by blocking closing the app while a save is in progress.

If there is really important content on it, you could try recovering it through a gzip-recovery tool because the save file is just a gzip archive which contains json data. If it is possible to recover the partially written document then it might be possible to append missing data to it to be able to import it again.

santiagocezar commented 2 weeks ago

I think I just had this happen to me, though I don't think there's much to recover as all it's left is an empty file :(

Looks like it truncates the file before saving, it'd be a lot safer to write all to a separate file, and then move the file over the original file (LibreOffice seems to do it this way)

That way if something fails all that gets lost is the latest changes, not the whole file (and you could also autosave into this file)

flxzt commented 1 week ago

I just pushed a fix that inhibits closing windows containing tabs where saves are currently in progress. This should fix the issue, will be included in the next release

Looks like it truncates the file before saving, it'd be a lot safer to write all to a separate file, and then move the file over the original file (LibreOffice seems to do it this way)

That's another improvement we should implement.

flxzt commented 2 days ago

with 4586ee10572fd9fd73fc51fc1ee5e5878cc99197 and the subsequent commits the app close is inhibited while saves are in progress.

For the improvement to save to a second file I'll open another issue.