insanum / sncli

Simplenote CLI
MIT License
396 stars 34 forks source link

Data recovery if crash during saving #53

Closed leonhandreke closed 6 years ago

leonhandreke commented 6 years ago

I experienced data loss today. I edited a note with vim, saved and quit, and when I came back to sncli, the UI was frozen. I quit sncli with Ctrl+C and my edit was lost.

This should never happen, there should be some sort of data recovery mechanism that ensures that after I have saved the file in vim, I can be sure not to lose its contents. I've lost data in the past due to my computer running out of battery while still editing the note (despite having saved it).

samuelallan72 commented 6 years ago

sncli creates a temporary file and passes that to the editor when you edit a note. This temporary file is then deleted once the editor closes and sncli saves the note. In late september ( https://github.com/insanum/sncli/commit/c233663028e4a593aaad283ba91e95d16a649ad8 ), the cfg_tempdir option was added which allows you to put the temporary directory somewhere persistent on disk so you can recover the note in the case of a lockup or shutdown.

leonhandreke commented 6 years ago

Thanks for the quick reply, I set it to ~/.cache/sncli, so next time this happens I'll be able to recover the data. I'm still thinking about whether this could be fixed in a more user-friendly way. Some ideas I had so far:

Since the problem is fixed for me personally, I'll close this issue for now. Thanks for your help!

samuelallan72 commented 6 years ago

@leonhandreke glad that fixes it for you! :)

Technically at the moment cfg_tempdir not a cache; it's purely a temporary place to store note content currently beiing edited - a communication between the editor and sncli. It's currently not possible to sync during editing with the current architecture. The running of the editor blocks sncli (no parallel processing).

It would seem to me that to support multiple sncli instances, sync while editing, etc., it would require a different architecture of the entire program, and a different method of storing note data on disk. :\