The attached patches (i) revert the previous data saving patch for
stable and (ii) implement a different, and safer, approach. There are
some issues here (e.g, with symlinks), but these already exist in the
code that makes user-requested backups. The only real change is to the
code that figures out to what name we should backup the original file.
So this seems about as safe as it could be.
The reason we need this patch for 2.1.x is that the more sophisticated
approach needs more refinement, and testing, that it can get before 2.1.1.
Here's a summary of what this patch does.
If the user has not requested that we backup the original file, we do so
anyway, not to file.lyx~ but to a temporary name of our own creation,
lyxbak-NUM-file.lyx, where NUM is some number we find that gives us a
non-existent file. Note that this filename depends upon which file we
are saving, and we try NUM up to 1024. So we should always be able to
find such a name, unless something very bad has happened.
If we are unable to backup the original file, we issue a warning and ask
the user if s'he wants to continue.
If the file is saved successfully, then we delete our temporary backup
file.
If the file is not saved successfully, then we attempt to move the
backup file back to the original location. If that fails, then we inform
the user that the original file can still be found at a new location.
I put a "return false" at the beginning of Buffer::writeFile() and
verified that the original file is properly restored. Since we move the
file back and forth unless it is a symlink, this should preserve
permissions as well.
Comments?
Richard