Fix Save when old .bak exists

If you save a ride and then delete it. The re-import and save
you will end up with two copies of the ride in the ride list.

This is because when we save the first time the original file
is renamed to e.g. ride.tcx.bak and the new ride.json is then
created. All is well.

But then delete the ride and it will rename ride.json to
ride.json.bak. Again, All is well.

Now, re-import the ride. We now have; ride.tcx.bak and
ride.json.bak and ride.tcx. Again, all is well.

But now, if you make changes and save it will attempt to
rename ride.tcx to ride.tcx.bak AND FAIL. This is because
the old ride.tcx.bak file is there. It will then create
ride.json. All is NOT well, since we have two rides with
the same date and time but different extensions.

This patch fixes this by unlinking ride.ext.bak before
trying to rename the file.

Fixes #348.
This commit is contained in:
Mark Liversedge
2011-08-03 19:42:07 +01:00
parent e41644c33f
commit 1d135aee5c

View File

@@ -150,8 +150,11 @@ MainWindow::saveSilent(RideItem *rideItem)
if (currentFI.baseName() != targetnosuffix) {
// rename as backup current if converting, or just delete it if its already .gc
if (convert) currentFile.rename(currentFile.fileName(), currentFile.fileName() + ".bak");
else currentFile.remove();
// unlink previous .bak if it is already there
if (convert) {
QFile::remove(currentFile.fileName()+".bak"); // ignore errors if not there
currentFile.rename(currentFile.fileName(), currentFile.fileName() + ".bak");
} else currentFile.remove();
convert = false; // we just did it already!
// set the new filename & Start time everywhere
@@ -182,6 +185,7 @@ MainWindow::saveSilent(RideItem *rideItem)
if (convert) {
// rename on disk
QFile::remove(currentFile.fileName()+".bak"); // ignore errors if not there
currentFile.rename(currentFile.fileName(), currentFile.fileName() + ".bak");
// rename in memory