New Discovery Algo: readability improvements
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 27 Aug 2018 13:10:12 +0000 (15:10 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:04 +0000 (10:58 +0100)
As proposed by ckamm on #6738

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

index 7807b8aac73a56c2bd525552ab4ea165a2ae1941..641aa43946b57c95d680e89fbb210d088c917c2e 100644 (file)
@@ -161,6 +161,7 @@ void ProcessDirectoryJob::start()
         csync_vio_local_closedir(dh);
     }
     _hasLocalEntries = true;
+    // Process is being called when both local and server entries are fetched.
     if (_hasServerEntries)
         process();
 }
@@ -398,6 +399,8 @@ void ProcessDirectoryJob::processFile(PathTuple path,
     if (recurseQueryServer != ParentNotChanged && !serverEntry.isValid())
         recurseQueryServer = ParentDontExist;
 
+    bool noServerEntry = _queryServer != ParentNotChanged && !serverEntry.isValid();
+
     if (_queryServer == NormalQuery && serverEntry.isValid()) {
         item->_checksumHeader = serverEntry.checksumHeader;
         item->_fileId = serverEntry.fileId;
@@ -664,13 +667,13 @@ void ProcessDirectoryJob::processFile(PathTuple path,
                 item->_type = ItemTypeVirtualFile;
             }
 
-            if (_queryServer != ParentNotChanged && !serverEntry.isValid()) {
+            if (noServerEntry) {
                 item->_instruction = CSYNC_INSTRUCTION_REMOVE;
                 item->_direction = SyncFileItem::Down;
             }
         } else if (dbEntry.isValid() && !typeChange && ((dbEntry._modtime == localEntry.modtime && dbEntry._fileSize == localEntry.size) || (localEntry.isDirectory && dbEntry._type == ItemTypeDirectory))) {
             // Local file unchanged.
-            if (_queryServer != ParentNotChanged && !serverEntry.isValid()) {
+            if (noServerEntry) {
                 item->_instruction = CSYNC_INSTRUCTION_REMOVE;
                 item->_direction = SyncFileItem::Down;
             } else if (!serverModified && dbEntry._inode != localEntry.inode) {
@@ -887,7 +890,7 @@ void ProcessDirectoryJob::processFile(PathTuple path,
                         }
 
                         qCInfo(lcDisco) << "Discovered" << item->_file << item->_instruction << item->_direction << item->isDirectory();
-                        bool recurse = checkPremission(item);
+                        bool recurse = checkPermissions(item);
                         if (recurse && item->isDirectory()) {
                             auto job = new ProcessDirectoryJob(item, recurseQueryServer, NormalQuery, _discoveryData, this);
                             job->_currentFolder = path;
@@ -905,7 +908,7 @@ void ProcessDirectoryJob::processFile(PathTuple path,
             }
         } else {
             item->_instruction = CSYNC_INSTRUCTION_SYNC;
-            if (_queryServer != ParentNotChanged && !serverEntry.isValid()) {
+            if (noServerEntry) {
                 // Special case! deleted on server, modified on client, the instruction is then NEW
                 item->_instruction = CSYNC_INSTRUCTION_NEW;
             }
@@ -930,12 +933,12 @@ void ProcessDirectoryJob::processFile(PathTuple path,
             }
         }
     } else if (_queryLocal == ParentNotChanged && dbEntry.isValid()) {
-        if (_queryServer != ParentNotChanged && !serverEntry.isValid()) {
+        if (noServerEntry) {
             // Not modified locally (ParentNotChanged), bit not on the server:  Removed on the server.
             item->_instruction = CSYNC_INSTRUCTION_REMOVE;
             item->_direction = SyncFileItem::Down;
         }
-    } else if (_queryServer != ParentNotChanged && !serverEntry.isValid()) {
+    } else if (noServerEntry) {
         // Not locally, not on the server. The entry is stale!
         qCInfo(lcDisco) << "Stale DB entry";
         return;
@@ -975,7 +978,7 @@ void ProcessDirectoryJob::processFile(PathTuple path,
 
 
     bool recurse = item->isDirectory() || localEntry.isDirectory || serverEntry.isDirectory;
-    if (!checkPremission(item))
+    if (!checkPermissions(item))
         recurse = false;
     if (_queryLocal != NormalQuery && _queryServer != NormalQuery && !item->_isRestoration)
         recurse = false;
@@ -1030,7 +1033,7 @@ void ProcessDirectoryJob::processBlacklisted(const PathTuple &path, const OCC::L
     }
 }
 
-bool ProcessDirectoryJob::checkPremission(const OCC::SyncFileItemPtr &item)
+bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
 {
     if (item->_direction != SyncFileItem::Up) {
         // Currently we only check server-side permissions
index 67a0b80672d9721246821d83c847c78f989c0682..97ca744b2834dea6758a70ddd2ccd669a72aca6f 100644 (file)
@@ -30,9 +30,9 @@ class ProcessDirectoryJob : public QObject
 public:
     enum QueryMode {
         NormalQuery,
-        ParentDontExist,
-        ParentNotChanged,
-        InBlackList
+        ParentDontExist, // Do not query this folder because it does not exist
+        ParentNotChanged, // No need to query this folder because it has not changed from what is in the DB
+        InBlackList // Do not query this folder because it is in th blacklist (remote entries only)
     };
     Q_ENUM(QueryMode)
     explicit ProcessDirectoryJob(const SyncFileItemPtr &dirItem, QueryMode queryServer, QueryMode queryLocal,
@@ -75,7 +75,7 @@ private:
     bool handleExcluded(const QString &path, bool isDirectory, bool isHidden, bool isSymlink);
     void processFile(PathTuple, const LocalInfo &, const RemoteInfo &, const SyncJournalFileRecord &dbEntry);
     // Return false if there is an error and that a directory must not be recursively be taken
-    bool checkPremission(const SyncFileItemPtr &item);
+    bool checkPermissions(const SyncFileItemPtr &item);
     void processBlacklisted(const PathTuple &, const LocalInfo &, const SyncJournalFileRecord &dbEntry);
     void subJobFinished();
     void progress();