Create backup file when writing new xml file?

Lubomir I. Ivanov neolit123 at
Sun Feb 16 15:46:52 UTC 2014

the patch has a small issue at windows.c,
but it does build without the extra { at:

if (wpath && wnewpath) {

On 16 February 2014 23:25, Linus Torvalds <torvalds at> wrote:
> On Sun, Feb 16, 2014 at 11:52 AM, Linus Torvalds
> <torvalds at> 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.
> 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.
> 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".
> 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.

apart from the above comment the 'subsurface_rename' wrapper looks fine.

> 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?
> 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.

i don't think we currently support MSVC at all (read that as: "it it's
highly unlikely it will build")
MINGW does have a 'strncasecmp' declaration in string.h, but it looks
like a wrapper for _stricmp from the MSVCRT library.

so AFAIK 'strncasecmp' can be used with MINGW.

> As mentioned, I don't even know if this is really the direction we
> want to go in.

i've tried opening and saving a file as quick test and it seems to work.


More information about the subsurface mailing list