Backup all config files in the config folder if there was a version change of the...
authorCamila <hello@camila.codes>
Tue, 27 Dec 2022 21:19:17 +0000 (22:19 +0100)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Mon, 30 Jan 2023 08:44:17 +0000 (09:44 +0100)
Signed-off-by: Camila <hello@camila.codes>
src/gui/application.cpp

index d6c6db292a7da8319717bbe65eeb88d2ff203a84..3b47300add987899d136e9438a81e56e6f68f5f9 100644 (file)
@@ -141,29 +141,31 @@ bool Application::configVersionMigration()
 
     // Did the client version change?
     // (The client version is adjusted further down)
-    bool versionChanged = configFile.clientVersionString() != MIRALL_VERSION_STRING;
-
-    if (versionChanged) {
-        QDir directory(configFile.configPath());
-        const auto anyConfigFileList = directory.entryInfoList({"*.cfg"}, QDir::Files);
-        for (const auto &file : anyConfigFileList) {
-            if (file.baseName() != APPLICATION_CONFIG_NAME) {
-                QFile::rename(file.canonicalFilePath(), configFile.configFile());
-                break;
-            }
-        }
-    }
+    const auto versionChanged = configFile.clientVersionString() != MIRALL_VERSION_STRING;
 
     // We want to message the user either for destructive changes,
     // or if we're ignoring something and the client version changed.
-    bool warningMessage = !deleteKeys.isEmpty() || (!ignoreKeys.isEmpty() && versionChanged);
+    auto warningMessage = !deleteKeys.isEmpty() || (!ignoreKeys.isEmpty() && versionChanged);
 
-    if (!versionChanged && !warningMessage)
+    if (!versionChanged && !warningMessage) {
         return true;
+    }
 
-    const auto backupFile = configFile.backup();
+    // back up all old config file
+    QStringList backupFilesList;
+    QDir directory(configFile.configPath());
+    const auto anyConfigFileList = directory.entryInfoList({"*.cfg"}, QDir::Files);
+    for (const auto &file : anyConfigFileList) {
+        const auto fileName = file.fileName();
+        backupFilesList.append(configFile.backup(fileName));
+        if (file.baseName() != APPLICATION_CONFIG_NAME) {
+            if (!QFile::rename(fileName, configFile.configFile())) {
+                qCWarning(lcApplication) << "Failed to rename configuration file from" << file.baseName() << "to" << configFile.configFile();
+            }
+        }
+    }
 
-    if (warningMessage) {
+    if (warningMessage || backupFilesList.count() > 0) {
         QString boldMessage;
         if (!deleteKeys.isEmpty()) {
             boldMessage = tr("Continuing will mean <b>deleting these settings</b>.");
@@ -180,7 +182,7 @@ bool Application::configVersionMigration()
                "%1<br>"
                "<br>"
                "The current configuration file was already backed up to <i>%2</i>.")
-                .arg(boldMessage, backupFile));
+                .arg(boldMessage, backupFilesList.join("<br>")));
         box.addButton(tr("Quit"), QMessageBox::AcceptRole);
         auto continueBtn = box.addButton(tr("Continue"), QMessageBox::DestructiveRole);