diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-03-24 18:15:23 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2022-03-24 22:16:50 +0300 |
commit | 2e7d662091076fb7bfb39b04f5c8dd1c5b53ca2f (patch) | |
tree | 5e99f2d439f98c46d8d7d05e75d33d117b97aefa /src/gui/folderman.cpp | |
parent | ffd941831c77ce8760dae821d6c02e7f1ec044cf (diff) |
Ensure the folder definition is initialised
Diffstat (limited to 'src/gui/folderman.cpp')
-rw-r--r-- | src/gui/folderman.cpp | 126 |
1 files changed, 62 insertions, 64 deletions
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index df643627e..a15d5b7c3 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -314,81 +314,79 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, } settings.endGroup(); - FolderDefinition folderDefinition; settings.beginGroup(folderAlias); - if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) { - const auto defaultJournalPath = [&account, folderDefinition] { - // if we would have booth the 2.9.0 file name and the lagacy file - // with the md5 infix we prefer the 2.9.0 version - const QDir info(folderDefinition.localPath()); - const QString defaultPath = SyncJournalDb::makeDbName(folderDefinition.localPath()); - if (info.exists(defaultPath)) { - return defaultPath; - } - // 2.6 - QString legacyPath = makeLegacyDbName(folderDefinition, account->account()); - if (info.exists(legacyPath)) { - return legacyPath; - } - // pre 2.6 - legacyPath.replace(QLatin1String(".sync_"), QLatin1String("._sync_")); - if (info.exists(legacyPath)) { - return legacyPath; - } + FolderDefinition folderDefinition = FolderDefinition::load(settings, folderAlias); + const auto defaultJournalPath = [&account, folderDefinition] { + // if we would have booth the 2.9.0 file name and the lagacy file + // with the md5 infix we prefer the 2.9.0 version + const QDir info(folderDefinition.localPath()); + const QString defaultPath = SyncJournalDb::makeDbName(folderDefinition.localPath()); + if (info.exists(defaultPath)) { return defaultPath; - }(); - - // migration: 2.10 did not specify a webdav url - if (folderDefinition._webDavUrl.isEmpty()) { - folderDefinition._webDavUrl = account->account()->davUrl(); } - - // Migration: Old settings don't have journalPath - if (folderDefinition.journalPath.isEmpty()) { - folderDefinition.journalPath = defaultJournalPath; + // 2.6 + QString legacyPath = makeLegacyDbName(folderDefinition, account->account()); + if (info.exists(legacyPath)) { + return legacyPath; } - - // Migration: ._ files sometimes can't be created. - // So if the configured journalPath has a dot-underscore ("._sync_*.db") - // but the current default doesn't have the underscore, switch to the - // new default if no db exists yet. - if (folderDefinition.journalPath.startsWith("._sync_") - && defaultJournalPath.startsWith(".sync_") - && !QFile::exists(folderDefinition.absoluteJournalPath())) { - folderDefinition.journalPath = defaultJournalPath; + // pre 2.6 + legacyPath.replace(QLatin1String(".sync_"), QLatin1String("._sync_")); + if (info.exists(legacyPath)) { + return legacyPath; } + return defaultPath; + }(); - // Migration: If an old .csync_journal.db is found, move it to the new name. - if (backwardsCompatible) { - SyncJournalDb::maybeMigrateDb(folderDefinition.localPath(), folderDefinition.absoluteJournalPath()); - } + // migration: 2.10 did not specify a webdav url + if (folderDefinition._webDavUrl.isEmpty()) { + folderDefinition._webDavUrl = account->account()->davUrl(); + } - auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode); - if (!vfs) { - // TODO: Must do better error handling - qFatal("Could not load plugin"); - } + // Migration: Old settings don't have journalPath + if (folderDefinition.journalPath.isEmpty()) { + folderDefinition.journalPath = defaultJournalPath; + } - if (Folder *f = addFolderInternal(std::move(folderDefinition), account, std::move(vfs))) { - // Migrate the old "usePlaceholders" setting to the root folder pin state - if (settings.value(versionC(), 1).toInt() == 1 - && settings.value(QLatin1String("usePlaceholders"), false).toBool()) { - qCInfo(lcFolderMan) << "Migrate: From usePlaceholders to PinState::OnlineOnly"; - f->setRootPinState(PinState::OnlineOnly); - } + // Migration: ._ files sometimes can't be created. + // So if the configured journalPath has a dot-underscore ("._sync_*.db") + // but the current default doesn't have the underscore, switch to the + // new default if no db exists yet. + if (folderDefinition.journalPath.startsWith("._sync_") + && defaultJournalPath.startsWith(".sync_") + && !QFile::exists(folderDefinition.absoluteJournalPath())) { + folderDefinition.journalPath = defaultJournalPath; + } - // Migration: Mark folders that shall be saved in a backwards-compatible way - if (backwardsCompatible) - f->setSaveBackwardsCompatible(true); - if (foldersWithPlaceholders) - f->setSaveInFoldersWithPlaceholders(); + // Migration: If an old .csync_journal.db is found, move it to the new name. + if (backwardsCompatible) { + SyncJournalDb::maybeMigrateDb(folderDefinition.localPath(), folderDefinition.absoluteJournalPath()); + } - // save possible changes from the migration - f->saveToSettings(); + auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode); + if (!vfs) { + // TODO: Must do better error handling + qFatal("Could not load plugin"); + } - scheduleFolder(f); - emit folderSyncStateChange(f); + if (Folder *f = addFolderInternal(std::move(folderDefinition), account, std::move(vfs))) { + // Migrate the old "usePlaceholders" setting to the root folder pin state + if (settings.value(versionC(), 1).toInt() == 1 + && settings.value(QLatin1String("usePlaceholders"), false).toBool()) { + qCInfo(lcFolderMan) << "Migrate: From usePlaceholders to PinState::OnlineOnly"; + f->setRootPinState(PinState::OnlineOnly); } + + // Migration: Mark folders that shall be saved in a backwards-compatible way + if (backwardsCompatible) + f->setSaveBackwardsCompatible(true); + if (foldersWithPlaceholders) + f->setSaveInFoldersWithPlaceholders(); + + // save possible changes from the migration + f->saveToSettings(); + + scheduleFolder(f); + emit folderSyncStateChange(f); } settings.endGroup(); } @@ -592,7 +590,7 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat return nullptr; } - FolderDefinition folderDefinition; + FolderDefinition folderDefinition(accountState->account()->davUrl()); folderDefinition.alias = alias; folderDefinition.setLocalPath(path); folderDefinition.setTargetPath(targetPath); |