mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Migrate all folders from a legacy config.
- Migrate only the current config in use by the legacy application. Signed-off-by: Camila <hello@camila.codes>
This commit is contained in:
parent
f69dea0a94
commit
c3feee1095
@ -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)
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user