New Discovery Algorithm: more cleanups
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 16 Oct 2018 09:03:46 +0000 (11:03 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:09 +0000 (10:58 +0100)
 - rename progress() to be more explicit
 - Make some more member of the discovery phase private

src/libsync/discovery.cpp
src/libsync/discovery.h
src/libsync/discoveryphase.cpp
src/libsync/discoveryphase.h

index 0a3367dcd01aa3cd2839e38a5a74b82bf18655e6..99c86d5dd801537adf660ec04fca027cec94123e 100644 (file)
@@ -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;
     }
index 6b11ff1381c4045d860035acf53eb9cf83a20693..a1402e3bbdbd174717c77c07dd8c5c57edf8134d 100644 (file)
@@ -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);
index 06bd6998abe1c509d50085c0f055b4c8e5f69218..d2ff2acafd7793003b287c663c6e2d5ecdb04a40 100644 (file)
@@ -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);
     }
 }
 
index beeaab6b485a6eae16abd599591166d72a33ad5f..06e7dd299cfdcc0f4e2a46d449b2190550043e6e 100644 (file)
@@ -129,6 +129,12 @@ class DiscoveryPhase : public QObject
 
     ProcessDirectoryJob *_currentRootJob = nullptr;
 
+    friend class ProcessDirectoryJob;
+    QMap<QString, SyncFileItemPtr> _deletedItem;
+    QMap<QString, ProcessDirectoryJob *> _queuedDeletedDirectories;
+    QMap<QString, QString> _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<bool(const QString &)> _shouldDiscoverLocaly;
 
@@ -150,9 +155,6 @@ public:
     void checkSelectiveSyncNewFolder(const QString &path, RemotePermissions rp,
         std::function<void(bool)> callback);
 
-    QMap<QString, SyncFileItemPtr> _deletedItem;
-    QMap<QString, ProcessDirectoryJob *> _queuedDeletedDirectories;
-    QMap<QString, QString> _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,