Deduplicate whitelistFolderPath and blacklistFolderPath
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 3 Aug 2023 07:34:39 +0000 (15:34 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 4 Aug 2023 09:44:23 +0000 (17:44 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folderman.cpp
src/gui/folderman.h

index efbf46d906f51846b01697393c19f21c3700eebb..f41a3142480b0f91318162cd0814dbb41b3a8c0f 100644 (file)
@@ -1259,7 +1259,7 @@ Folder *FolderMan::folderForPath(const QString &path)
     return it != folders.cend() ? *it : nullptr;
 }
 
-void FolderMan::whitelistFolderPath(const QString &path)
+void FolderMan::addFolderToSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType list)
 {
     const auto folder = folderForPath(path);
     if (!folder) {
@@ -1268,19 +1268,27 @@ void FolderMan::whitelistFolderPath(const QString &path)
 
     const QString folderPath = folder->cleanPath() + QLatin1Char('/');
     const auto relPath = path.mid(folderPath.length());
-    folder->whitelistPath(relPath);
+
+    switch (list) {
+    case SyncJournalDb::SelectiveSyncListType::SelectiveSyncWhiteList:
+        folder->whitelistPath(relPath);
+        break;
+    case SyncJournalDb::SelectiveSyncListType::SelectiveSyncBlackList:
+        folder->blacklistPath(relPath);
+        break;
+    default:
+        Q_UNREACHABLE();
+    }
 }
 
-void FolderMan::blacklistFolderPath(const QString &path)
+void FolderMan::whitelistFolderPath(const QString &path)
 {
-    const auto folder = folderForPath(path);
-    if (!folder) {
-        return;
-    }
+    addFolderToSelectiveSyncList(path, SyncJournalDb::SelectiveSyncListType::SelectiveSyncWhiteList);
+}
 
-    const QString folderPath = folder->cleanPath() + QLatin1Char('/');
-    const auto relPath = path.mid(folderPath.length());
-    folder->blacklistPath(relPath);
+void FolderMan::blacklistFolderPath(const QString &path)
+{
+    addFolderToSelectiveSyncList(path, SyncJournalDb::SelectiveSyncListType::SelectiveSyncBlackList);
 }
 
 QStringList FolderMan::findFileInLocalFolders(const QString &relPath, const AccountPtr acc)
index a79f1119355c2176a8378161d0f6c2c8d43f952e..684ba29829e41f0631916590ba91270b07e531c6 100644 (file)
@@ -358,6 +358,8 @@ private:
 
     [[nodiscard]] bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const;
 
+    void addFolderToSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType list);
+
     QSet<Folder *> _disabledFolders;
     Folder::Map _folderMap;
     QString _folderConfigPath;