Auto-save mechanism

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Auto-save mechanism

Post by wmayer »

There is now an auto-save and a recovery tool implemented in FreeCAD.

How it works:
1. When a FreeCAD instance gets started it creates a lock file FreeCAD_PID.lock (e.g. FreeCAD_1276.lock) and for each created document a transient directory is created of the form FreeCAD_Doc_HASH_PID (e.g.FreeCAD_Doc_afda3e1d-482d-4fb2-b313-8dc45672d7b3_da39a3_1276)

2. For each created document after a certain time there is a project file stored called 'fc_recovery_file.fcstd' inside the document's transient directory.
Inside this directory there is a second file created called 'fc_recovery_file.xml' which contains some meta-information about the fcstd file which cannot be stored directly there.

3. When FreeCAD crashes then the lock file and the transient directory won't be deleted.

4. When FreeCAD starts the next time it searches for .lock with a different process ID and then searches for transient directories with these process IDs. Afterwards it checks if inside the found directories there is the file 'fc_recovery_file.fcstd'. Additionally, it checks for the 'fc_recovery_file.xml' and reads the status flag. If this file doesn't exist or if the flag is set to 'Created' then the .fcstd file is marked for recovery.

5. Now a dialog comes up with all .fcstd files marked for recovery. The user has to press the 'Start Recovery' button and must wait until the procedure has finished. The dialog shows which project files could be recovered and which not. At this time the xml files are re-written with the status set to 'Success' or 'Failure' to avoid to try to recover the files the next time FreeCAD starts.

NOTE: The recovery files won't be deleted.

Parameters for the auto.save option and recovery tool are inside the group 'Document':
* RecoveryEnabled: a boolean to enable or disable the recovery tool
* AutoSaveEnabled: a boolean to enable or disable the auto-saving
* AutoSaveTimeout: an integer to set the timeout when the recovery files should be created. The default value is 15, i.e. 15 min. Possible values are in the range 1-60 min.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Auto-save mechanism

Post by DeepSOIC »

Sounds awesome!
drei
Posts: 479
Joined: Sun May 11, 2014 7:47 pm
Location: Mexico
Contact:

Re: Auto-save mechanism

Post by drei »

This is a godsend. Thank you very much. :D
Need help? Feel free to ask, but please read the guidelines first
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: Auto-save mechanism

Post by galou_breizh »

FreeCAD just crashed so I had the opportunity to test the auto-save mechanism.

It worked pretty well, thanks Werner for it !

There is something I'm not sure about but I don't know how to provoke a crash to test it:

Do saved files also go through the recovery process?

I had the impression they do. I had untouched files opened and when the recovery process went through, these files were opened and had the 'modified' status.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Auto-save mechanism

Post by wmayer »

There is something I'm not sure about but I don't know how to provoke a crash to test it:
Simply open a terminal window and enter

Code: Select all

killall FreeCAD
On Windows kill it with the task manager.
Do saved files also go through the recovery process?
It depends. If the time stamp of the saved regular project file is newer than of the recovery file then it doesn't go through the recovery process because you have no gain of information if you restored it. In the output window you should get a warning that the recovery file is ignored.

If the time stamp of the recovery file is newer then it goes normally through the recovery process.
I had the impression they do. I had untouched files opened and when the recovery process went through, these files were opened and had the 'modified' status.
All recovered documents have the 'modified' status because otherwise if you have stored your document before the crash you could close it without being asked to save it. Then you would lose the recovered information.

However, the recovery function does NOT delete any data. All what it does is opening the file fc_recovery_file.xml and changes the status from 'Created' to something else (to 'Success' when it could be restored, 'Failure' if it failed, 'Deprecated' if the saved project is newer and 'Unknown' in all other cases).

So, if you want to re-process the recovery you have to open the fc_recovery_file.xml file and manually change the status back to 'Created'. But be careful: this way the xml file gets a newer time stamp and you have to check if the saved project file is what you actually want to keep.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Auto-save mechanism

Post by jmaustpc »

wmayer wrote:Simply open a terminal window and enter

Code: Select all
killall FreeCAD

On Windows kill it with the task manager.
If anyone out there wants to do this graphically on Kubuntu and presumably other KDE distros, you can do so by running the "system monitor", right click on FreeCAD (if it is running) and then "send signal" "Kill"

Its under K menu, applications, system, system monitor, ...process table tab...
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Auto-save mechanism

Post by Chris_G »

If anyone out there wants to do this graphically on Kubuntu and presumably other KDE distros, you can do so by running the "system monitor", right click on FreeCAD (if it is running) and then "send signal" "Kill"

Its under K menu, applications, system, system monitor, ...process table tab...
There is also a keyboard shortcut ( Kubuntu also ) :
- CTRL + ALT + Escape
- the mouse pointer change to a red "pirate skull" ( not sure it is the right word )
- Left clic the window to kill, or right clic to abort killing operation
User avatar
saso
Veteran
Posts: 1920
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Auto-save mechanism

Post by saso »

I think it would be good if there would be a way in the gui to (1) skip / ignore the recovery so that the dialog window would not show up on every FC start if there are files that can be recovered and (2) remove the files from the recovery dialog and temp folder, ex. select the file in the dialog, left mouse click, remove... (some very bad things can start to happen on Windows in the temp folder gets to big, been there :roll: ).
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Auto-save mechanism

Post by wmayer »

(1) skip / ignore the recovery so that the dialog window would not show up
Did you check the preferences? There is an option to switch off the auto-recovery and there is an option to switch off the auto-save.
(2) remove the files from the recovery dialog and temp folder
I also thought about adding this possibility.
User avatar
NormandC
Veteran
Posts: 18587
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Auto-save mechanism

Post by NormandC »

This feature may be creating problems on Windows.

viewtopic.php?p=116675#p116646
Post Reply