Create backup file when writing new xml file?

David Faure faure at kde.org
Thu Feb 20 00:07:46 UTC 2014


On Monday 17 February 2014 14:34:17 Thiago Macieira wrote:
> Em seg 17 fev 2014, às 10:42:44, David Faure escreveu:
> > On Sunday 16 February 2014 19:52:36 Thiago Macieira wrote:
> > > The simplest operation is to write to a temp file, then rename the
> > > original
> > > to  the backup name, then rename the temp to the original name. However,
> > > what happens if the application crashes between renames? You've got a
> > > temp
> > > and a backup, but no file.
> > 
> > Isn't that good enough? That's what backups are for. The usual way to use
> > a
> > backup is for the user to rename it to the proper name (e.g. remove
> > ".backup") and open it with the application, isn't it?
> 
> That's not an atomic operation. There's a brief moment when a file with the
> original name does not exist anymore.

I know. But again: how do you use a backup file? You have to open a file 
manager and rename it to the main file name, or you have to use the open 
dialog in the application, with a permissive filter, and open it.
This is no different whether the main file exists or has been deleted. In both 
cases manual user action is needed to use the backup file.

If you say such manual action should never be required, then either the backup 
file is useless, or the app needs to provide a GUI for it.

My conclusion: for a document, user action is required to use the backup file 
anyway, and losing the main file on a crash *is* one of the few cases where 
the backup file actually turns out to be useful. And for an internal file 
(e.g. config file), a backup file is not useful (since the user doesn't know 
about it), so plain QSaveFile is sufficient.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5



More information about the subsurface mailing list