From b6ff17c50be2339ba1dcfa9a8b0afeccacd6d6e5 Mon Sep 17 00:00:00 2001 From: Joshua Sterner Date: Thu, 9 May 2019 01:05:49 -0700 Subject: [PATCH 1/2] Fixed Issue #1000 - Subfolders of moved folders not synced Signed-off-by: Joshua Sterner --- src/gui/folderwatcher.cpp | 18 ++++++++++++++++++ src/gui/folderwatcher.h | 3 +++ test/testfolderwatcher.cpp | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/gui/folderwatcher.cpp b/src/gui/folderwatcher.cpp index d8136ff361..65e68cb36f 100644 --- a/src/gui/folderwatcher.cpp +++ b/src/gui/folderwatcher.cpp @@ -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); } diff --git a/src/gui/folderwatcher.h b/src/gui/folderwatcher.h index a6cf006e20..b07c33a100 100644 --- a/src/gui/folderwatcher.h +++ b/src/gui/folderwatcher.h @@ -26,6 +26,7 @@ #include #include #include +#include class QTimer; @@ -120,6 +121,8 @@ private: Folder *_folder; bool _isReliable = true; + void appendSubPaths(QDir dir, QStringList& subPaths); + friend class FolderWatcherPrivate; }; } diff --git a/test/testfolderwatcher.cpp b/test/testfolderwatcher.cpp index d908568282..b5dba5fbc8 100644 --- a/test/testfolderwatcher.cpp +++ b/test/testfolderwatcher.cpp @@ -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); From bd9fcd88d85f48889e5e6fd55456cec7b123a22c Mon Sep 17 00:00:00 2001 From: Joshua Sterner Date: Thu, 9 May 2019 03:45:41 -0700 Subject: [PATCH 2/2] testMove3LevelDirWithFile now uses mv function to move the directory Signed-off-by: Joshua Sterner --- test/testfolderwatcher.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/testfolderwatcher.cpp b/test/testfolderwatcher.cpp index b5dba5fbc8..fdd97701db 100644 --- a/test/testfolderwatcher.cpp +++ b/test/testfolderwatcher.cpp @@ -146,9 +146,7 @@ private slots: 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()); + mv(_rootPath + "/a0 ", _rootPath + "/a"); QVERIFY(waitForPathChanged(_rootPath + "/a/b/c/empty.txt")); }