From: Olivier Goffart Date: Mon, 27 Aug 2018 13:10:12 +0000 (+0200) Subject: New Discovery Algo: readability improvements X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~516 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=21fe54fb13d6523168ad4dcd46c05f1daa314261;p=nextcloud-desktop.git New Discovery Algo: readability improvements As proposed by ckamm on #6738 --- diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 7807b8aac..641aa4394 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -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 diff --git a/src/libsync/discovery.h b/src/libsync/discovery.h index 67a0b8067..97ca744b2 100644 --- a/src/libsync/discovery.h +++ b/src/libsync/discovery.h @@ -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();