Settings: Don't migrate settings on access error #5499 (#5523)
authorckamm <mail@ckamm.de>
Wed, 8 Feb 2017 13:28:50 +0000 (14:28 +0100)
committerMarkus Goetz <markus@woboq.com>
Wed, 8 Feb 2017 13:28:50 +0000 (14:28 +0100)
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
src/gui/accountmanager.h
src/gui/application.cpp

index 9d8b3ed41b06dd4906258240e98af66c3b9a045e..84ad5d4a5b7b899eda4b3cd95d8f30d07d369c86 100644 (file)
@@ -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());
 
index 70a625da1dfd27b08f3f4c8f9a259e824c6ed9dd..2dcb9c88d7d97b8193038cde278266a7be4d22e6 100644 (file)
@@ -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();
 
index d67a0537cd2ffe95fe54da4156386fd5d11cb586..d8c8b6fd4d34c8c07e3d56908e6736b20cb03f19 100644 (file)
@@ -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);