From c700b8c5c5ea522ffeedd4950d2e89f81f67cfb4 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 3 Jan 2016 16:25:18 +0200 Subject: [PATCH] Move the 'qBittorrent-resume' file even when no magnets were recovered. Also make sure to rename it with a unique name. Closes #4334. --- src/app/upgrade.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/app/upgrade.h b/src/app/upgrade.h index 0a9ff75c8..7af4be152 100644 --- a/src/app/upgrade.h +++ b/src/app/upgrade.h @@ -118,14 +118,15 @@ bool upgrade(bool ask = true) QString oldResumeFilename = oldResumeSettings->fileName(); QVariantHash oldResumeData = oldResumeSettings->value("torrents").toHash(); delete oldResumeSettings; - if (oldResumeData.isEmpty()) + bool oldResumeWasEmpty = oldResumeData.isEmpty(); + if (oldResumeWasEmpty) Utils::Fs::forceRemove(oldResumeFilename); QString backupFolderPath = Utils::Fs::expandPathAbs(Utils::Fs::QDesktopServicesDataLocation() + "BT_backup"); QDir backupFolderDir(backupFolderPath); QStringList backupFiles = backupFolderDir.entryList(QStringList() << QLatin1String("*.fastresume"), QDir::Files, QDir::Unsorted); - if (backupFiles.isEmpty() && oldResumeData.isEmpty()) return true; + if (backupFiles.isEmpty() && oldResumeWasEmpty) return true; if (ask && !userAcceptsUpgrade()) return false; int maxPrio = 0; @@ -168,8 +169,17 @@ bool upgrade(bool ask = true) } } - if (!oldResumeData.isEmpty()) - QFile(oldResumeFilename).rename(oldResumeFilename + ".bak"); + if (!oldResumeWasEmpty) { + int counter = 0; + QString backupResumeFilename = oldResumeFilename + ".bak"; + + while (QFile::exists(backupResumeFilename)) { + ++counter; + backupResumeFilename = oldResumeFilename + ".bak" + QString::number(counter); + } + + QFile::rename(oldResumeFilename, backupResumeFilename); + } return true; }