From 20e7aff393437d356dd0dd19a2340d94e43e2387 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 13 May 2018 11:47:03 +0300 Subject: [PATCH] Delete non-commited fastresume files Old v3.3.x format had a number at the end indicating the queue position. The naming scheme was '.fastresume.'. However, QSaveFile, which uses QTemporaryFile internally, might leave non-commited files behind eg after a crash. These files have the naming scheme '.fastresume.XXXXXX' where each X is a random character. We try to detect the latter and remove it without "migrating" the fastresume to the new saving system. --- src/app/upgrade.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/upgrade.h b/src/app/upgrade.h index 813eba0f5..18791b50b 100644 --- a/src/app/upgrade.h +++ b/src/app/upgrade.h @@ -114,12 +114,27 @@ bool upgradeResumeFile(const QString &filepath, const QVariantHash &oldTorrent = bool v3_3 = false; int queuePosition = 0; QString outFilePath = filepath; - QRegExp rx(QLatin1String("([A-Fa-f0-9]{40})\\.fastresume\\.(\\d+)$")); + QRegExp rx(QLatin1String("([A-Fa-f0-9]{40})\\.fastresume\\.(.+)$")); if (rx.indexIn(filepath) != -1) { - // old v3.3.x format + // Old v3.3.x format had a number at the end indicating the queue position. + // The naming scheme was '.fastresume.'. + // However, QSaveFile, which uses QTemporaryFile internally, might leave + // non-commited files behind eg after a crash. These files have the + // naming scheme '.fastresume.XXXXXX' where each X is a random + // character. So we detect if the last part is present. Then check if it + // is 6 chars long. If all the 6 chars are digits we assume it is an old + // v3.3.x format. Otherwise it is considered a non-commited fastresume + // and is deleted, because it may be a corrupted/incomplete fastresume. + // NOTE: When the upgrade code is removed, we must continue to perform + // cleanup of non-commited QSaveFile/QTemporaryFile fastresumes queuePosition = rx.cap(2).toInt(); + if ((rx.cap(2).size() == 6) && (queuePosition <= 99999)) { + Utils::Fs::forceRemove(filepath); + return true; + } + v3_3 = true; - outFilePath.replace(QRegExp("\\.\\d+$"), ""); + outFilePath.replace(QRegExp("\\.fastresume\\..+$"), ".fastresume"); } else { queuePosition = fastOld.dict_find_int_value("qBt-queuePosition", 0);