From 4198d9f420f630f2f346a123422f937bfbec88d2 Mon Sep 17 00:00:00 2001 From: ckamm Date: Wed, 8 Feb 2017 14:28:50 +0100 Subject: [PATCH] Settings: Don't migrate settings on access error #5499 (#5523) Previously, we'd try migrating from legacy settings if reading the settings failed with an error. Now, we try again after a couple of seconds and eventually give up. --- src/gui/accountmanager.cpp | 11 ++++++++++- src/gui/accountmanager.h | 4 +++- src/gui/application.cpp | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 9d8b3ed41..84ad5d4a5 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -46,11 +46,17 @@ AccountManager *AccountManager::instance() bool AccountManager::restore() { auto settings = Utility::settingsWithGroup(QLatin1String(accountsC)); + if (settings->status() != QSettings::NoError) { + qDebug() << "Could not read settings from" << settings->fileName() + << settings->status(); + return false; + } // If there are no accounts, check the old format. if (settings->childGroups().isEmpty() && !settings->contains(QLatin1String(versionC))) { - return restoreFromLegacySettings(); + restoreFromLegacySettings(); + return true; } foreach (const auto& accountId, settings->childGroups()) { @@ -69,6 +75,9 @@ bool AccountManager::restore() bool AccountManager::restoreFromLegacySettings() { + qDebug() << "Migrate: restoreFromLegacySettings, checking settings group" + << Theme::instance()->appName(); + // try to open the correctly themed settings auto settings = Utility::settingsWithGroup(Theme::instance()->appName()); diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h index 70a625da1..2dcb9c88d 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -36,7 +36,9 @@ public: /** * Creates account objects from a given settings file. - * return true if the account was restored + * + * Returns false if there was an error reading the settings, + * but note that settings not existing is not an error. */ bool restore(); diff --git a/src/gui/application.cpp b/src/gui/application.cpp index d67a0537c..d8c8b6fd4 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -156,7 +156,23 @@ Application::Application(int &argc, char **argv) : connect(this, SIGNAL(messageReceived(QString, QObject*)), SLOT(slotParseMessage(QString, QObject*))); - AccountManager::instance()->restore(); + if (!AccountManager::instance()->restore()) { + // If there is an error reading the account settings, try again + // after a couple of seconds, if that fails, give up. + // (non-existence is not an error) + Utility::sleep(5); + if (!AccountManager::instance()->restore()) { + qDebug() << "Could not read the account settings, quitting"; + QMessageBox::critical( + 0, + tr("Error accessing the configuration file"), + tr("There was an error while accessing the configuration " + "file at %1.").arg(ConfigFile().configFile()), + tr("Quit ownCloud")); + QTimer::singleShot(0, qApp, SLOT(quit())); + return; + } + } FolderMan::instance()->setSyncEnabled(true); -- 2.30.2