Fixed Issue #1000 - Subfolders of moved folders not synced
authorJoshua Sterner <joshua.s.sterner@gmail.com>
Thu, 9 May 2019 08:05:49 +0000 (01:05 -0700)
committerJoshua Sterner <joshua.s.sterner@gmail.com>
Thu, 9 May 2019 11:12:33 +0000 (04:12 -0700)
Signed-off-by: Joshua Sterner <joshua.s.sterner@gmail.com>
src/gui/folderwatcher.cpp
src/gui/folderwatcher.h
test/testfolderwatcher.cpp

index d8136ff3610bea9b9f61149fbc8ba9275cf3ee25..65e68cb36fbf8720d7729613aad713ea99ed927d 100644 (file)
@@ -75,9 +75,27 @@ bool FolderWatcher::isReliable() const
     return _isReliable;
 }
 
+void FolderWatcher::appendSubPaths(QDir dir, QStringList& subPaths) {
+    QStringList newSubPaths = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
+    for (int i = 0; i < newSubPaths.size(); i++) {
+        QString path = dir.path() + "/" + newSubPaths[i];
+        QFileInfo fileInfo(path);
+        subPaths.append(path);
+        if (fileInfo.isDir()) {
+            QDir dir(path);
+            appendSubPaths(dir, subPaths);
+        }
+    }
+}
+
 void FolderWatcher::changeDetected(const QString &path)
 {
+    QFileInfo fileInfo(path);
     QStringList paths(path);
+    if (fileInfo.isDir()) {
+        QDir dir(path);
+        appendSubPaths(dir, paths);
+    }
     changeDetected(paths);
 }
 
index a6cf006e20cd8b49940f74a87150103f0d8cf16b..b07c33a100d2b435d41ee2a1ea60f75765588704 100644 (file)
@@ -26,6 +26,7 @@
 #include <QHash>
 #include <QScopedPointer>
 #include <QSet>
+#include <QDir>
 
 class QTimer;
 
@@ -120,6 +121,8 @@ private:
     Folder *_folder;
     bool _isReliable = true;
 
+    void appendSubPaths(QDir dir, QStringList& subPaths);
+
     friend class FolderWatcherPrivate;
 };
 }
index d908568282ef6fa3b12fdc3372fc7ef20883bff2..b5dba5fbc80ed816caabfb861a8ce3e4b80ad90f 100644 (file)
@@ -140,6 +140,19 @@ private slots:
         QVERIFY(waitForPathChanged(file));
     }
 
+    void testMove3LevelDirWithFile() {
+        QString file(_rootPath + "/a0/b/c/empty.txt");
+        mkdir(_rootPath + "/a0");
+        mkdir(_rootPath + "/a0/b");
+        mkdir(_rootPath + "/a0/b/c");
+        touch(file);
+        QString cmd = QString("mv " + _rootPath + "/a0 " + _rootPath + "/a");
+        qDebug() << "Command: " << cmd;
+        system(cmd.toLocal8Bit());
+        QVERIFY(waitForPathChanged(_rootPath + "/a/b/c/empty.txt"));
+    }
+
+
     void testCreateADir() {
         QString file(_rootPath+"/a1/b1/new_dir");
         mkdir(file);