Migrate selective sync db list.
authorCamila <hello@camila.codes>
Sun, 27 Aug 2023 21:32:05 +0000 (23:32 +0200)
committerCamila <hello@camila.codes>
Fri, 1 Sep 2023 13:09:29 +0000 (15:09 +0200)
- Refactor migration of blacklisted folders.
- Only change selective sync list if needed.

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

index 2aa8ee48e673e9cbf95645996b8eb3379b80a323..92b05d269b316b105bd5a558b8b06f073f01aef8 100644 (file)
@@ -893,6 +893,14 @@ void Folder::blacklistPath(const QString &path)
     appendPathToSelectiveSyncList(path, SyncJournalDb::SelectiveSyncBlackList);
 }
 
+void Folder::migrateBlackListPath(const QString &legacyPath)
+{
+    if (legacyPath.startsWith(QLatin1Char('/'))) {
+        removePathFromSelectiveSyncList(legacyPath, SyncJournalDb::SelectiveSyncBlackList);
+        blacklistPath(legacyPath.mid(1));
+    }
+}
+
 bool Folder::isFileExcludedAbsolute(const QString &fullPath) const
 {
     return _engine->excludedFiles().isExcluded(fullPath, path(), _definition.ignoreHiddenFiles);
index f0459a9f03ba7f7fd8381838a380a04337087c70..edc8484b4c923960db97de5c5dea49e3659e61c7 100644 (file)
@@ -303,6 +303,7 @@ public:
 
     void whitelistPath(const QString &path);
     void blacklistPath(const QString &path);
+    void migrateBlackListPath(const QString &legacyPath);
 
 signals:
     void syncStateChange();
index 3c6f012e1f4fe6f95ae3eb56933dd69778015dbf..b69c1cfd426b06a1f4aa8296e9b3844a5bd4fe5e 100644 (file)
@@ -563,10 +563,21 @@ void FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Accoun
             folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles;
 
             if (const auto folder = addFolderInternal(folderDefinition, accountState, std::make_unique<VfsOff>())) {
-                const auto blackList = settings.value(QLatin1String("blackList")).toStringList();
-                if (!blackList.empty()) {
+                auto ok = true;
+                if (const auto legacyBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
+                                                                                      &ok);ok && !legacyBlacklist.isEmpty()) {
+                    qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
+                    for(const auto &legacyFolder : legacyBlacklist) {
+                      folder->migrateBlackListPath(legacyFolder);
+                    }
+                } else {
+                    qCInfo(lcFolderMan) << "There was a problem retriving the database selective sync for " << folder;
+                }
+
+                const auto settingLegacyBlacklist = settings.value(QLatin1String("blackList")).toStringList();
+                if (!settingLegacyBlacklist.empty()) {
                     //migrate settings
-                    folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList);
+                    folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, settingLegacyBlacklist);
                     settings.remove(QLatin1String("blackList"));
                     // FIXME: If you remove this codepath, you need to provide another way to do
                     // this via theme.h or the normal FolderMan::setupFolders
@@ -574,7 +585,7 @@ void FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Accoun
 
                 folder->saveToSettings();
 
-                qCInfo(lcFolderMan) << "Migrated!" << folder;
+                qCInfo(lcFolderMan) << "Migrated!" << folder->path();
                 settings.sync();
 
                 if (!folder) {