From 17de46cec2bef59016985ccbb71c69356bf2b755 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 27 Jun 2023 15:56:30 +0800 Subject: [PATCH] Clean up declaration of DiscoveryPhase::checkSelectiveSyncNewFolder by using const auto, renaming single letter variables, more Signed-off-by: Claudio Cambra --- src/libsync/discoveryphase.cpp | 76 +++++++++++++++++++--------------- src/libsync/discoveryphase.h | 8 +++- 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 3142a2968a..3fef366c56 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -82,8 +82,48 @@ bool DiscoveryPhase::isInSelectiveSyncBlackList(const QString &path) const return false; } -void DiscoveryPhase::checkSelectiveSyncNewFolder(const QString &path, RemotePermissions remotePerm, - std::function callback) +void DiscoveryPhase::checkFolderSizeLimit(const QString &path, + const std::function 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() << "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 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() << "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 */ diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index 36b07b874d..9485003711 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -255,10 +255,14 @@ class DiscoveryPhase : public QObject [[nodiscard]] bool isInSelectiveSyncBlackList(const QString &path) const; + void checkFolderSizeLimit(const QString &path, + const std::function 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 callback); + void checkSelectiveSyncNewFolder(const QString &path, + const RemotePermissions rp, + const std::function callback); /** Given an original path, return the target path obtained when renaming is done. *