Editor file saving process... Data loss potential?

I was wondering if someone understanding the GUI editor could describe the process by which a file is saved.

I recently had a cause-unknown crash (I suspect some windows, not octave, related issue) where I typed exit in the command window to close octave, got the prompt to save a file in the editor, clicked the button to save it, and with other things happening on the PC, octave went “Not Responding” and some time later i had to kill the process.

I reopened Octave and the file I was editing only to find it was blank. 0 bytes, no text. The file was there, but empty. (Thankfully I had a backup and only lost ~an hour of work.) Haven’t been able to deliberately recreate the crashing event during a save.

However it happened, the fact that I lost both the in-memory and on-disk data was concerning. Does the editor just directly overwrite the open file with contents from memory? Create a new blank file and then dump the memory contents into it?

Assuming it doesn’t already, would it be possible to have a process where it first writes the contents to a temporary file, if successful copies that file over the actual file, then if successful deletes the temp file? (I know this is a standard word processor file save approach.). This way at several points prior data is preserved such that a process failure wouldn’t take the old data with it.

1 Like

The process for saving the editor contents into the related files is done directly and without any temporary file. But you are bringing up an important point. I will change this behavior in the default branch.

2 Likes

This feature is added to the default branch with changeset 2dc31151ca27.

2 Likes