Create backup file when writing new xml file?

Dirk Hohndel dirk at hohndel.org
Sun Feb 16 14:21:58 UTC 2014


On Sun, 2014-02-16 at 13:25 -0800, Linus Torvalds wrote:
> On Sun, Feb 16, 2014 at 11:52 AM, Linus Torvalds
> <torvalds at linux-foundation.org> wrote:
> >
> > I'm still thinking about better file formats and backup, but haven't come
> > up with anything that I'm actually happy about.
> 
> So I really haven't gotten anywhere about a new format, because
> anything that just gets rid of the nasty xml is too much pain for the
> gain, and the more ambitious ideas I have have lots of other
> painpoints.

What I really am hoping for is to get to something with a git-like
functionality where it is easy for us to host a server for people (but
equally easy for people to host their own). As soon as we have an
Android build that is more than just a toy people will want to
synchronize and I don't want to push people into dropbox or something
like that...

> Anyway, one thing I do think we should do is be more careful about not
> overwriting our old xml file. In particular, right now if we crash
> while writing the new xml file, everything is gone, both new and old.

I completely agree. I had this happen a few times myself (but of course
my files are on my git server).

> Now, we could fix that crash case by just being much more careful when
> writing: write to a different filename, fsync() the new file, and then
> rename() the new file over the old one. Except as usual, windows is a
> pain for any filesystem activity, and I have no idea how well fsync
> works, and I *know* the rename needs some magic too.
> 
> And even if we do that careful write, that will fix the "oops, we
> crashed while writing" problem, but not the "uhhuh, I made a mistake
> and overwrote the old xml file".

Been there SO MANY TIMES :-)

> So here's a rather less ambitious patch that still does the "windows
> needs magic rename support because their VFS layer is using that
> insane crap UCS-2 wchar idiocy", but just says "let's rename the old
> file from "xml" to "bak" before writing the new file.
> 
> I don't personally really need it, since I use git to track my dives
> anyway, so I have backups of my own, but I know others don't. So..
> Comments? Is this just a bad idea?

I think it's a really good idea. This has been on my todo list since
forever.

> Also, I know Windows also has issues with strncasecmp (that I use to
> test that the backup really only gets written if the filename is
> called ".xml") under msvc, but I really don't know if anybody really
> builds it that way. So I just added a comment. A
> "-Dstrncasecmp=_strnicmp" in the MSVC-specific build file might be
> sufficient. Or maybe there is some Qt helper. Whatever.
> 
> As mentioned, I don't even know if this is really the direction we
> want to go in.

I will take the patch as is and ask the Windows expert (Lubomir) and the
Qt export (Thiago) to see if there is something we should do
differently.

/D



More information about the subsurface mailing list