From: Camila Date: Sun, 27 Aug 2023 20:19:04 +0000 (+0200) Subject: Migrate all folders from a legacy config. X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~9^2~20^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c3feee109529cdcd2360582e10243c9e2ec18a48;p=nextcloud-desktop.git Migrate all folders from a legacy config. - Migrate only the current config in use by the legacy application. Signed-off-by: Camila --- diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index f41a31424..3c6f012e1 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -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) diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 684ba2982..731b37d98 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -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.