From 56e9f6f1be26aa1352d19c3d4761ba79c3281322 Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Mon, 5 Jan 2015 09:35:55 +0100 Subject: [PATCH] Better checks before applying update Check that each file was downloaded and that the size matches. We don't check the signatures inside qTox so as not to freeze the GUI during startup. The updater will check the signatures anyway We now try to restart update downloads if we detect that it was interrupted --- src/autoupdate.cpp | 16 +++++++++++++++- src/autoupdate.h | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/autoupdate.cpp b/src/autoupdate.cpp index 23ca5d651..4d6dbb87e 100644 --- a/src/autoupdate.cpp +++ b/src/autoupdate.cpp @@ -370,7 +370,7 @@ bool AutoUpdater::isLocalUpdateReady() if (!updateDir.exists()) return false; - // Check that we have a flist and that every file on the diff exists + // Check that we have a flist and generate a diff QFile updateFlistFile(updateDirStr+"flist"); if (!updateFlistFile.open(QIODevice::ReadOnly)) return false; @@ -380,9 +380,23 @@ bool AutoUpdater::isLocalUpdateReady() QList updateFlist = parseFlist(updateFlistData); QList diff = genUpdateDiff(updateFlist); + // If the update wasn't downloaded correctly, redownload it + // We don't check signatures to not block qTox too long, the updater will do it anyway for (UpdateFileMeta fileMeta : diff) + { if (!QFile::exists(updateDirStr+fileMeta.installpath)) + { + QtConcurrent::run(&AutoUpdater::downloadUpdate); return false; + } + + QFile f(updateDirStr+fileMeta.installpath); + if (f.size() != (int64_t)fileMeta.size) + { + QtConcurrent::run(&AutoUpdater::downloadUpdate); + return false; + } + } return true; } diff --git a/src/autoupdate.h b/src/autoupdate.h index 6d766c4ea..3937e3b20 100644 --- a/src/autoupdate.h +++ b/src/autoupdate.h @@ -78,9 +78,9 @@ public: /// Will try to download an update, if successful returns true and qTox will apply it after a restart /// Will try to follow qTox's proxy settings, may block and processEvents static bool downloadUpdate(); - /// Returns true if an update is downloaded and ready to be installed - /// If so, call installLocalUpdate. If not, call downloadUpdate. - /// This only checks that we downloaded an update and didn't stop in the middle, not that every file is still valid + /// Returns true if an update is downloaded and ready to be installed, + /// if so, call installLocalUpdate. + /// If an update was partially downloaded, the function will resume asynchronously and return false static bool isLocalUpdateReady(); /// Launches the qTox updater to try to install the local update and exits immediately /// Will not check that the update actually exists, use isLocalUpdateReady first for that