Migrate all folders from a legacy config.
authorCamila <hello@camila.codes>
Sun, 27 Aug 2023 20:19:04 +0000 (22:19 +0200)
committerCamila <hello@camila.codes>
Fri, 1 Sep 2023 13:09:28 +0000 (15:09 +0200)
- Migrate only the current config in use by the legacy application.

Signed-off-by: Camila <hello@camila.codes>
src/gui/folderman.cpp
src/gui/folderman.h

index f41a3142480b0f91318162cd0814dbb41b3a8c0f..3c6f012e1f4fe6f95ae3eb56933dd69778015dbf 100644 (file)
@@ -172,9 +172,6 @@ int FolderMan::setupFolders()
 
     unloadAndDeleteAllFolders();
 
-    QStringList skipSettingsKeys;
-    backwardMigrationSettingsKeys(&skipSettingsKeys, &skipSettingsKeys);
-
     auto settings = ConfigFile::settingsWithGroup(QLatin1String("Accounts"));
     const auto accountsWithSettings = settings->childGroups();
     if (accountsWithSettings.isEmpty()) {
@@ -187,6 +184,9 @@ int FolderMan::setupFolders()
 
     qCInfo(lcFolderMan) << "Setup folders from settings file";
 
+    //    this is done in Application::configVersionMigration
+    QStringList skipSettingsKeys;
+    backwardMigrationSettingsKeys(&skipSettingsKeys, &skipSettingsKeys);
     const auto accounts = AccountManager::instance()->accounts();
     for (const auto &account : accounts) {
         const auto id = account->account()->id();
@@ -353,19 +353,17 @@ int FolderMan::setupFoldersMigration()
     qCInfo(lcFolderMan) << "Setup folders from " << configPath << "(migration)";
 
     QDir dir(configPath);
-    //We need to include hidden files just in case the alias starts with '.'
+    //We need to include hidden files just in case the alias starts with '.'    
     dir.setFilter(QDir::Files | QDir::Hidden);
-    const auto dirFiles = dir.entryList();
+    //Exclude previous backed up configs e.g. oc.cfg.backup_20230831_133749_4.0.0
+    //only need the current config in use by the legacy application
+    const auto dirFiles = dir.entryList({"*.cfg"});
 
-    // Normally there should be only one account when migrating. TODO: Change
+    // Normally there should be only one account when migrating. TODO: Should assume only one legacy config file
     const auto accountState = AccountManager::instance()->accounts().value(0).data();
     for (const auto &fileName : dirFiles) {
         const auto fullFilePath = dir.filePath(fileName);
-        const auto folder = setupFolderFromOldConfigFile(fullFilePath, accountState);
-        if (folder) {
-            scheduleFolder(folder);
-            emit folderSyncStateChange(folder);
-        }
+        setupFolderFromOldConfigFile(fullFilePath, accountState);
     }
 
     emit folderListChanged(_folderMap);
@@ -481,8 +479,7 @@ QString FolderMan::unescapeAlias(const QString &alias)
     return a;
 }
 
-// WARNING: Do not remove this code, it is used for predefined/automated deployments (2016)
-Folder *FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, AccountState *accountState)
+void FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, AccountState *accountState)
 {
     qCInfo(lcFolderMan) << "  ` -> setting up:" << fileNamePath;
     QString escapedFileNamePath(fileNamePath);
@@ -498,7 +495,7 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Acc
     }
     if (!cfgFile.isReadable()) {
         qCWarning(lcFolderMan) << "Cannot read folder definition for alias " << cfgFile.filePath();
-        return nullptr;
+        return;
     }
 
     QSettings settings(escapedFileNamePath, QSettings::IniFormat);
@@ -509,12 +506,12 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Acc
     const auto groups = settings.childGroups();
     if (groups.isEmpty()) {
         qCWarning(lcFolderMan) << "empty file:" << cfgFile.filePath();
-        return nullptr;
+        return;
     }
 
     if (!accountState) {
         qCCritical(lcFolderMan) << "can't create folder without an account";
-        return nullptr;
+        return;
     }
 
     settings.beginGroup(settingsAccountsC);
@@ -580,7 +577,12 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Acc
                 qCInfo(lcFolderMan) << "Migrated!" << folder;
                 settings.sync();
 
-                return folder;
+                if (!folder) {
+                    continue;
+                }
+
+                scheduleFolder(folder);
+                emit folderSyncStateChange(folder);
             }
 
             settings.endGroup();
@@ -590,7 +592,7 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Acc
         settings.endGroup();
     }
 
-    return nullptr;
+    return;
 }
 
 void FolderMan::slotFolderSyncPaused(Folder *f, bool paused)
index 684ba29829e41f0631916590ba91270b07e531c6..731b37d98ac5dd8347e240bf0170065fa6f2e481 100644 (file)
@@ -119,10 +119,10 @@ public:
     Folder *folder(const QString &);
 
     /**
-     * Migrate accounts from owncloud < 2.0
+     * Migrate accounts from owncloud
      * Creates a folder for a specific configuration, identified by alias.
      */
-    Folder *setupFolderFromOldConfigFile(const QString &, AccountState *account);
+    void setupFolderFromOldConfigFile(const QString &, AccountState *account);
 
     /**
      * Ensures that a given directory does not contain a sync journal file.