]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Clean up declaration of DiscoveryPhase::checkSelectiveSyncNewFolder by using const...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 27 Jun 2023 07:56:30 +0000 (15:56 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 4 Aug 2023 09:40:35 +0000 (17:40 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/libsync/discoveryphase.cpp
src/libsync/discoveryphase.h

index 3142a2968a749294417b4abf093ad53b78b1e43d..3fef366c5634791976382151a45d900a7f3cff4c 100644 (file)
@@ -82,8 +82,48 @@ bool DiscoveryPhase::isInSelectiveSyncBlackList(const QString &path) const
     return false;
 }
 
-void DiscoveryPhase::checkSelectiveSyncNewFolder(const QString &path, RemotePermissions remotePerm,
-    std::function<void(bool)> callback)
+void DiscoveryPhase::checkFolderSizeLimit(const QString &path,
+                                          const std::function<void(bool)> callback)
+{
+    const auto limit = _syncOptions._newBigFolderSizeLimit;
+    if (limit < 0 || _syncOptions._vfs->mode() != Vfs::Off) {
+        // no limit, everything is allowed;
+        return callback(false);
+    }
+
+    // do a PROPFIND to know the size of this folder
+    const auto propfindJob = new PropfindJob(_account, _remoteFolder + path, this);
+    propfindJob->setProperties(QList<QByteArray>() << "resourcetype"
+                                                   << "http://owncloud.org/ns:size");
+
+    connect(propfindJob, &PropfindJob::finishedWithError, this, [=] { return callback(false); });
+    connect(propfindJob, &PropfindJob::result, this, [=](const QVariantMap &values) {
+        auto result = values.value(QLatin1String("size")).toLongLong();
+        if (result >= limit) {
+            // we tell the UI there is a new folder
+            emit newBigFolder(path, false);
+            return callback(true);
+        } else {
+            // it is not too big, put it in the white list (so we will not do more query for the children)
+            // and and do not block.
+            auto sanitisedPath = path;
+            if (!sanitisedPath.endsWith(QLatin1Char('/'))) {
+                sanitisedPath += QLatin1Char('/');
+            }
+
+            _selectiveSyncWhiteList.insert(std::upper_bound(_selectiveSyncWhiteList.begin(),
+                                                            _selectiveSyncWhiteList.end(),
+                                                            sanitisedPath),
+                                           sanitisedPath);
+            return callback(false);
+        }
+    });
+    propfindJob->start();
+}
+
+void DiscoveryPhase::checkSelectiveSyncNewFolder(const QString &path,
+                                                 const RemotePermissions remotePerm,
+                                                 const std::function<void(bool)> callback)
 {
     if (_syncOptions._confirmExternalStorage && _syncOptions._vfs->mode() == Vfs::Off
         && remotePerm.hasPermission(RemotePermissions::IsMounted)) {
@@ -107,37 +147,7 @@ void DiscoveryPhase::checkSelectiveSyncNewFolder(const QString &path, RemotePerm
         return callback(false);
     }
 
-    auto limit = _syncOptions._newBigFolderSizeLimit;
-    if (limit < 0 || _syncOptions._vfs->mode() != Vfs::Off) {
-        // no limit, everything is allowed;
-        return callback(false);
-    }
-
-    // do a PROPFIND to know the size of this folder
-    auto propfindJob = new PropfindJob(_account, _remoteFolder + path, this);
-    propfindJob->setProperties(QList<QByteArray>() << "resourcetype"
-                                                   << "http://owncloud.org/ns:size");
-    QObject::connect(propfindJob, &PropfindJob::finishedWithError,
-        this, [=] { return callback(false); });
-    QObject::connect(propfindJob, &PropfindJob::result, this, [=](const QVariantMap &values) {
-        auto result = values.value(QLatin1String("size")).toLongLong();
-        if (result >= limit) {
-            // we tell the UI there is a new folder
-            emit newBigFolder(path, false);
-            return callback(true);
-        } else {
-            // it is not too big, put it in the white list (so we will not do more query for the children)
-            // and and do not block.
-            auto p = path;
-            if (!p.endsWith(QLatin1Char('/')))
-                p += QLatin1Char('/');
-            _selectiveSyncWhiteList.insert(
-                std::upper_bound(_selectiveSyncWhiteList.begin(), _selectiveSyncWhiteList.end(), p),
-                p);
-            return callback(false);
-        }
-    });
-    propfindJob->start();
+    checkFolderSizeLimit(path, callback);
 }
 
 /* Given a path on the remote, give the path as it is when the rename is done */
index 36b07b874daf90404b3af9eeb6cd109bbf1b4e2c..948500371117e19abfc6ec12920a9b5f9a20e007 100644 (file)
@@ -255,10 +255,14 @@ class DiscoveryPhase : public QObject
 
     [[nodiscard]] bool isInSelectiveSyncBlackList(const QString &path) const;
 
+    void checkFolderSizeLimit(const QString &path,
+                             const std::function<void(bool)> callback);
+
     // Check if the new folder should be deselected or not.
     // May be async. "Return" via the callback, true if the item is blacklisted
-    void checkSelectiveSyncNewFolder(const QString &path, RemotePermissions rp,
-        std::function<void(bool)> callback);
+    void checkSelectiveSyncNewFolder(const QString &path,
+                                     const RemotePermissions rp,
+                                     const std::function<void(bool)> callback);
 
     /** Given an original path, return the target path obtained when renaming is done.
      *