Remove SyncFileItem::_isDirectory
authorJocelyn Turcotte <jturcotte@woboq.com>
Thu, 24 Aug 2017 15:31:46 +0000 (17:31 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:33 +0000 (22:01 +0200)
It's always equivalent to _type == SyncFileItem::Directory.

13 files changed:
src/gui/folder.cpp
src/libsync/owncloudpropagator.cpp
src/libsync/progressdispatcher.h
src/libsync/propagateremotedelete.cpp
src/libsync/propagateremotedelete.h
src/libsync/propagateremotemove.cpp
src/libsync/propagateremotemove.h
src/libsync/propagatorjobs.cpp
src/libsync/propagatorjobs.h
src/libsync/syncengine.cpp
src/libsync/syncfileitem.h
src/libsync/syncresult.cpp
test/testsyncengine.cpp

index f5374b257c03f11dd81b8e349d22c1e352153322..961e8754c99b441312f546b3840d49c8e7370708 100644 (file)
@@ -840,10 +840,10 @@ void Folder::slotTransmissionProgress(const ProgressInfo &pi)
 void Folder::slotItemCompleted(const SyncFileItemPtr &item)
 {
     // add new directories or remove gone away dirs to the watcher
-    if (item->_isDirectory && item->_instruction == CSYNC_INSTRUCTION_NEW) {
+    if (item->isDirectory() && item->_instruction == CSYNC_INSTRUCTION_NEW) {
         FolderMan::instance()->addMonitorPath(alias(), path() + item->_file);
     }
-    if (item->_isDirectory && item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
+    if (item->isDirectory() && item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
         FolderMan::instance()->removeMonitorPath(alias(), path() + item->_file);
     }
 
index 7550838e7845c886b2bb8199f9468fc469370331..7af77926c17e427dd7eee59ff6966320ae796c34 100644 (file)
@@ -291,7 +291,7 @@ bool PropagateItemJob::checkForProblemsWithShared(int httpStatusCode, const QStr
     PropagateItemJob *newJob = NULL;
 
     if (httpStatusCode == 403 && propagator()->isInSharedDirectory(_item->_file)) {
-        if (!_item->_isDirectory) {
+        if (!_item->isDirectory()) {
             SyncFileItemPtr downloadItem(new SyncFileItem(*_item));
             if (downloadItem->_instruction == CSYNC_INSTRUCTION_NEW
                 || downloadItem->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE) {
@@ -363,7 +363,7 @@ PropagateItemJob *OwncloudPropagator::createJob(const SyncFileItemPtr &item)
             return new PropagateRemoteDelete(this, item);
     case CSYNC_INSTRUCTION_NEW:
     case CSYNC_INSTRUCTION_TYPE_CHANGE:
-        if (item->_isDirectory) {
+        if (item->isDirectory()) {
             if (item->_direction == SyncFileItem::Down) {
                 auto job = new PropagateLocalMkdir(this, item);
                 job->setDeleteExistingFile(deleteExisting);
@@ -439,7 +439,7 @@ void OwncloudPropagator::start(const SyncFileItemVector &items)
                     delDirJob->increaseAffectedCount();
                 }
                 continue;
-            } else if (item->_isDirectory
+            } else if (item->isDirectory()
                 && (item->_instruction == CSYNC_INSTRUCTION_NEW
                        || item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE)) {
                 // create a new directory within a deleted directory? That can happen if the directory
@@ -463,7 +463,7 @@ void OwncloudPropagator::start(const SyncFileItemVector &items)
             directories.pop();
         }
 
-        if (item->_isDirectory) {
+        if (item->isDirectory()) {
             PropagateDirectory *dir = new PropagateDirectory(this, item);
 
             if (item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE
index f7015f6c55afa4dc59e1dc2deb1c2dc30f4e5628..b51be9810aaa9f4cd23715d154a8197b58e6a59c 100644 (file)
@@ -103,7 +103,7 @@ public:
     /** Return true if the size needs to be taken in account in the total amount of time */
     static inline bool isSizeDependent(const SyncFileItem &item)
     {
-        return !item._isDirectory && (item._instruction == CSYNC_INSTRUCTION_CONFLICT
+        return !item.isDirectory() && (item._instruction == CSYNC_INSTRUCTION_CONFLICT
                                          || item._instruction == CSYNC_INSTRUCTION_SYNC
                                          || item._instruction == CSYNC_INSTRUCTION_NEW
                                          || item._instruction == CSYNC_INSTRUCTION_TYPE_CHANGE);
index d66cb2d91bb5514de5b5300d27475d8a79717ffe..73f5c8240953aa90d92c8963da44ac23643b51e7 100644 (file)
@@ -120,7 +120,7 @@ void PropagateRemoteDelete::slotDeleteJobFinished()
         return;
     }
 
-    propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->_isDirectory);
+    propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->isDirectory());
     propagator()->_journal->commit("Remote Remove");
     done(SyncFileItem::Success);
 }
index c4367b3acf0c89a8097fccde80f4ded0ee5f3c0b..6246f7cbf0bbf0bdefd129a3f351744ed1570c68 100644 (file)
@@ -54,7 +54,7 @@ public:
     void start() Q_DECL_OVERRIDE;
     void abort() Q_DECL_OVERRIDE;
 
-    bool isLikelyFinishedQuickly() Q_DECL_OVERRIDE { return !_item->_isDirectory; }
+    bool isLikelyFinishedQuickly() Q_DECL_OVERRIDE { return !_item->isDirectory(); }
 
 private slots:
     void slotDeleteJobFinished();
index 69979b1a97b428aef66d9c8001c9fb9a5b88138c..a457365646652758795a28bbd8786745f88582e9 100644 (file)
@@ -187,7 +187,7 @@ void PropagateRemoteMove::finalize()
         return;
     }
 
-    if (_item->_isDirectory) {
+    if (_item->isDirectory()) {
         if (!adjustSelectiveSync(propagator()->_journal, _item->_file, _item->_renameTarget)) {
             done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
             return;
index 3180712df0b357d0d1067cdb4cddf5ebc31308ad..bf6661a6560b389bb22539d248cb709b4bc4ac28 100644 (file)
@@ -57,7 +57,7 @@ public:
     }
     void start() Q_DECL_OVERRIDE;
     void abort() Q_DECL_OVERRIDE;
-    JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->_isDirectory ? WaitForFinished : FullParallelism; }
+    JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->isDirectory() ? WaitForFinished : FullParallelism; }
 
     /**
      * Rename the directory in the selective sync list
index 769408dfb3d87f04b25632aa4c99d04d8cb9b879..de9339996e8b6f085e4273c0ecef6f7f4414c1cd 100644 (file)
@@ -121,7 +121,7 @@ void PropagateLocalRemove::start()
         return;
     }
 
-    if (_item->_isDirectory) {
+    if (_item->isDirectory()) {
         if (QDir(filename).exists() && !removeRecursively(QString())) {
             done(SyncFileItem::NormalError, _error);
             return;
@@ -135,7 +135,7 @@ void PropagateLocalRemove::start()
         }
     }
     propagator()->reportProgress(*_item, 0);
-    propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->_isDirectory);
+    propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->isDirectory());
     propagator()->_journal->commit("Local remove");
     done(SyncFileItem::Success);
 }
@@ -245,7 +245,7 @@ void PropagateLocalRename::start()
         record._checksumHeader = oldRecord._checksumHeader;
     }
 
-    if (!_item->_isDirectory) { // Directories are saved at the end
+    if (!_item->isDirectory()) { // Directories are saved at the end
         if (!propagator()->_journal->setFileRecord(record)) {
             done(SyncFileItem::FatalError, tr("Error writing metadata to the database"));
             return;
index 2f7c53df7858836a8b676dfb25af5dc267caa001..04c09cd48df836839be2623e321161b727855bb3 100644 (file)
@@ -91,6 +91,6 @@ public:
     {
     }
     void start() Q_DECL_OVERRIDE;
-    JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->_isDirectory ? WaitForFinished : FullParallelism; }
+    JobParallelism parallelism() Q_DECL_OVERRIDE { return _item->isDirectory() ? WaitForFinished : FullParallelism; }
 };
 }
index 38353f9eb1ba943497827c0dcc7ae6c52b80e3c5..f42b5d2d7626f4e77e4b2f55932c3384e60af138 100644 (file)
@@ -564,7 +564,6 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other,
         dir = SyncFileItem::None;
         // For directories, metadata-only updates will be done after all their files are propagated.
         if (!isDirectory) {
-            item->_isDirectory = isDirectory;
             emit syncItemDiscovered(*item);
 
             // Update the database now already:  New remote fileid or Etag or RemotePerm
@@ -655,7 +654,6 @@ int SyncEngine::treewalkFile(csync_file_stat_t *file, csync_file_stat_t *other,
     }
 
     item->_direction = dir;
-    item->_isDirectory = isDirectory;
     if (instruction != CSYNC_INSTRUCTION_NONE) {
         // check for blacklisting of this item.
         // if the item is on blacklist, the instruction was set to ERROR
@@ -1196,7 +1194,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
             (*it)->_status = SyncFileItem::FileIgnored;
             (*it)->_errorString = tr("Ignored because of the \"choose what to sync\" blacklist");
 
-            if ((*it)->_isDirectory) {
+            if ((*it)->isDirectory()) {
                 auto it_base = it;
                 for (SyncFileItemVector::iterator it_next = it + 1; it_next != syncItems.end() && (*it_next)->_file.startsWith(path); ++it_next) {
                     it = it_next;
@@ -1221,7 +1219,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
                             if (parent_it == syncItems.end() || (*parent_it)->destination() != parentDir) {
                                 break;
                             }
-                            ASSERT((*parent_it)->_isDirectory);
+                            ASSERT((*parent_it)->isDirectory());
                             if ((*parent_it)->_instruction != CSYNC_INSTRUCTION_IGNORE) {
                                 break; // already changed
                             }
@@ -1249,7 +1247,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
             if (perms.isNull()) {
                 // No permissions set
                 break;
-            } else if ((*it)->_isDirectory && !perms.contains("K")) {
+            } else if ((*it)->isDirectory() && !perms.contains("K")) {
                 qCWarning(lcEngine) << "checkForPermission: ERROR" << (*it)->_file;
                 (*it)->_instruction = CSYNC_INSTRUCTION_ERROR;
                 (*it)->_status = SyncFileItem::NormalError;
@@ -1271,7 +1269,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
                     (*it)->_errorString = tr("Not allowed because you don't have permission to add parent folder");
                 }
 
-            } else if (!(*it)->_isDirectory && !perms.contains("C")) {
+            } else if (!(*it)->isDirectory() && !perms.contains("C")) {
                 qCWarning(lcEngine) << "checkForPermission: ERROR" << (*it)->_file;
                 (*it)->_instruction = CSYNC_INSTRUCTION_ERROR;
                 (*it)->_status = SyncFileItem::NormalError;
@@ -1318,7 +1316,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
                 (*it)->_isRestoration = true;
                 (*it)->_errorString = tr("Not allowed to remove, restoring");
 
-                if ((*it)->_isDirectory) {
+                if ((*it)->isDirectory()) {
                     // restore all sub items
                     for (SyncFileItemVector::iterator it_next = it + 1;
                          it_next != syncItems.end() && (*it_next)->_file.startsWith(path); ++it_next) {
@@ -1345,7 +1343,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
                 // not delete permission we fast forward the iterator and leave the
                 // delete jobs intact. It is not physically tried to remove this files
                 // underneath, propagator sees that.
-                if ((*it)->_isDirectory) {
+                if ((*it)->isDirectory()) {
                     // put a more descriptive message if a top level share dir really is removed.
                     if (it == syncItems.begin() || !(path.startsWith((*(it - 1))->_file))) {
                         (*it)->_errorString = tr("Local files and share folder removed.");
@@ -1375,9 +1373,9 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
             if (isRename || destPerms.isNull()) {
                 // no need to check for the destination dir permission
                 destinationOK = true;
-            } else if ((*it)->_isDirectory && !destPerms.contains("K")) {
+            } else if ((*it)->isDirectory() && !destPerms.contains("K")) {
                 destinationOK = false;
-            } else if (!(*it)->_isDirectory && !destPerms.contains("C")) {
+            } else if (!(*it)->isDirectory() && !destPerms.contains("C")) {
                 destinationOK = false;
             }
 
@@ -1398,7 +1396,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
 #ifdef OWNCLOUD_RESTORE_RENAME /* We don't like the idea of renaming behind user's back, as the user may be working with the files */
             if (!sourceOK && (!destinationOK || isRename)
                 // (not for directory because that's more complicated with the contents that needs to be adjusted)
-                && !(*it)->_isDirectory) {
+                && !(*it)->isDirectory()) {
                 // Both the source and the destination won't allow move.  Move back to the original
                 std::swap((*it)->_file, (*it)->_renameTarget);
                 (*it)->_direction = SyncFileItem::Down;
@@ -1426,7 +1424,7 @@ void SyncEngine::checkForPermission(SyncFileItemVector &syncItems)
                 _anotherSyncNeeded = ImmediateFollowUp;
 
 
-                if ((*it)->_isDirectory) {
+                if ((*it)->isDirectory()) {
                     for (SyncFileItemVector::iterator it_next = it + 1;
                          it_next != syncItems.end() && (*it_next)->destination().startsWith(path); ++it_next) {
                         it = it_next;
index 9ea4e4d4577f2f9d08add8f609cc4c2ac4af0083..88ef5ee6dfc0d9c1f5a8c5757c43fae39e484788 100644 (file)
@@ -89,7 +89,6 @@ public:
     SyncFileItem()
         : _type(UnknownType)
         , _direction(None)
-        , _isDirectory(false)
         , _serverHasIgnoredFiles(false)
         , _hasBlacklistEntry(false)
         , _errorMayBeBlacklisted(false)
@@ -158,6 +157,11 @@ public:
         return _file.isEmpty();
     }
 
+    bool isDirectory() const
+    {
+        return _type == SyncFileItem::Directory;
+    }
+
     /**
      * True if the item had any kind of error.
      *
@@ -179,7 +183,6 @@ public:
     QString _renameTarget;
     Type _type BITFIELD(3);
     Direction _direction BITFIELD(3);
-    bool _isDirectory BITFIELD(1);
     bool _serverHasIgnoredFiles BITFIELD(1);
 
     /// Whether there's an entry in the blacklist table.
index 88e78320b07146936b6efd35462edf208cb6856b..52ce018d14f3169a1c2d062b8b7b6533eeef0f53 100644 (file)
@@ -132,7 +132,7 @@ void SyncResult::processCompletedItem(const SyncFileItemPtr &item)
         _foundFilesNotSynced = true;
     }
 
-    if (item->_isDirectory && (item->_instruction == CSYNC_INSTRUCTION_NEW
+    if (item->isDirectory() && (item->_instruction == CSYNC_INSTRUCTION_NEW
                                   || item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE
                                   || item->_instruction == CSYNC_INSTRUCTION_REMOVE
                                   || item->_instruction == CSYNC_INSTRUCTION_RENAME)) {
index 4baa43a13a047ecc4598b268f465d29f54b0f35c..d96c40695219164995023f3ba15ebfaf68e2d4e8 100644 (file)
@@ -309,7 +309,7 @@ private slots:
         QSet<QString> seen;
         for(const QList<QVariant> &args : completeSpy) {
             auto item = args[0].value<SyncFileItemPtr>();
-            qDebug() << item->_file << item->_isDirectory << item->_status;
+            qDebug() << item->_file << item->isDirectory() << item->_status;
             QVERIFY(!seen.contains(item->_file)); // signal only sent once per item
             seen.insert(item->_file);
             if (item->_file == "Y/Z/d2") {