From: Olivier Goffart Date: Tue, 16 Oct 2018 09:03:46 +0000 (+0200) Subject: New Discovery Algorithm: more cleanups X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~490 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1c2a3279bbd3ccc424c51f6246bf1fb958f90c90;p=nextcloud-desktop.git New Discovery Algorithm: more cleanups - rename progress() to be more explicit - Make some more member of the discovery phase private --- diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 0a3367dcd..99c86d5dd 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -1178,7 +1178,7 @@ void ProcessDirectoryJob::subJobFinished() QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs); } -int ProcessDirectoryJob::progress(int nbJobs) +int ProcessDirectoryJob::processSubJobs(int nbJobs) { if (_queuedJobs.empty() && _runningJobs.empty() && _pendingAsyncJobs == 0) { _pendingAsyncJobs = -1; // We're finished, we don't want to emit finished again @@ -1204,7 +1204,7 @@ int ProcessDirectoryJob::progress(int nbJobs) int started = 0; foreach (auto *rj, _runningJobs) { - started += rj->progress(nbJobs - started); + started += rj->processSubJobs(nbJobs - started); if (started >= nbJobs) return started; } diff --git a/src/libsync/discovery.h b/src/libsync/discovery.h index 6b11ff138..a1402e3bb 100644 --- a/src/libsync/discovery.h +++ b/src/libsync/discovery.h @@ -25,20 +25,21 @@ namespace OCC { class SyncJournalDb; /** - * Job that handle the discovering of a directory. + * Job that handles the discovering of a directory. * * This includes: * - Do a DiscoverySingleDirectoryJob network job which will do a PROPFIND of this directory * - Stat all the entries in the local file system for this directory - * - Merge all invormation (and the information from the database) in order to know what need + * - Merge all information (and the information from the database) in order to know what needs * to be done for every file within this directory. * - For every sub-directory within this directory, "recursively" create a new ProcessDirectoryJob * - * This job is tightly couple with the DiscoveryPhase class. + * This job is tightly coupled with the DiscoveryPhase class. * - * After being start()'ed, one must call progress() on this job until it emit finished(). + * After being start()'ed, one must call processSubJobs() on this job until it emits finished(). * This job will call DiscoveryPhase::scheduleMoreJobs when one of its sub-jobs is finished. - * DiscoveryPhase::scheduleMoreJobs is the one which will call progress(). + * DiscoveryPhase::scheduleMoreJobs is the one which will call processSubJobs(). + * Results are fed outwards via DiscoveryPhase::itemDiscovered */ class ProcessDirectoryJob : public QObject { @@ -63,7 +64,7 @@ public: } void start(); /** Start up to nbJobs, return the number of job started */ - int progress(int nbJobs); + int processSubJobs(int nbJobs); SyncFileItemPtr _dirItem; @@ -94,6 +95,7 @@ private: return result; } }; + // Called once _serverEntries and _localEntries are filled void process(); // return true if the file is excluded bool handleExcluded(const QString &path, bool isDirectory, bool isHidden, bool isSymlink); diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 06bd6998a..d2ff2acaf 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -169,7 +169,7 @@ void DiscoveryPhase::scheduleMoreJobs() { auto limit = qMax(1, _syncOptions._parallelNetworkJobs); if (_currentRootJob && _currentlyActiveJobs < limit) { - _currentRootJob->progress(limit - _currentlyActiveJobs); + _currentRootJob->processSubJobs(limit - _currentlyActiveJobs); } } diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index beeaab6b4..06e7dd299 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -129,6 +129,12 @@ class DiscoveryPhase : public QObject ProcessDirectoryJob *_currentRootJob = nullptr; + friend class ProcessDirectoryJob; + QMap _deletedItem; + QMap _queuedDeletedDirectories; + QMap _renamedItems; // map source -> destinations + int _currentlyActiveJobs = 0; + public: QString _localDir; // absolute path to the local directory. ends with '/' QString _remoteFolder; // remote folder, ends with '/' @@ -139,7 +145,6 @@ public: QStringList _selectiveSyncWhiteList; ExcludedFiles *_excludes; QString _invalidFilenamePattern; // FIXME: maybe move in ExcludedFiles - int _currentlyActiveJobs = 0; bool _ignoreHiddenFiles = false; std::function _shouldDiscoverLocaly; @@ -150,9 +155,6 @@ public: void checkSelectiveSyncNewFolder(const QString &path, RemotePermissions rp, std::function callback); - QMap _deletedItem; - QMap _queuedDeletedDirectories; - QMap _renamedItems; // map source -> destinations /** Given an original path, return the target path obtained when renaming is done. * * Note that it only considers parent directory renames. So if A/B got renamed to C/D,