From f8f3190cb4717808db1cceb8d47dd431bcf33c4a Mon Sep 17 00:00:00 2001 From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Wed, 16 Sep 2020 19:50:16 +0200 Subject: [PATCH] Fix missing subdirectory discovery on move operations in macOS. Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Add qAsConst to avoid detaching Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Changed callchain to find and return possibly coalesced paths Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Removed another qAsConst remnant, more func const-correctness. Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- src/gui/folderwatcher_mac.cpp | 23 ++++++++++++++++++++--- src/gui/folderwatcher_mac.h | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/gui/folderwatcher_mac.cpp mode change 100644 => 100755 src/gui/folderwatcher_mac.h diff --git a/src/gui/folderwatcher_mac.cpp b/src/gui/folderwatcher_mac.cpp old mode 100644 new mode 100755 index 3fa10f7b1..ee2314168 --- a/src/gui/folderwatcher_mac.cpp +++ b/src/gui/folderwatcher_mac.cpp @@ -19,6 +19,7 @@ #include +#include #include @@ -90,8 +91,6 @@ void FolderWatcherPrivate::startWatching() FSEventStreamContext ctx = { 0, this, nullptr, nullptr, nullptr }; - // TODO: Add kFSEventStreamCreateFlagFileEvents ? - _stream = FSEventStreamCreate(nullptr, &callback, &ctx, @@ -105,9 +104,27 @@ void FolderWatcherPrivate::startWatching() FSEventStreamStart(_stream); } +QStringList FolderWatcherPrivate::addCoalescedPaths(const QStringList &paths) const +{ + QStringList coalescedPaths; + for (const auto &eventPath : paths) { + if (QDir(eventPath).exists()) { + QDirIterator it(eventPath, QDir::AllDirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + while (it.hasNext()) { + auto subfolder = it.next(); + if (!paths.contains(subfolder)) { + coalescedPaths.append(subfolder); + } + } + } + } + return (paths + coalescedPaths); +} + void FolderWatcherPrivate::doNotifyParent(const QStringList &paths) { - _parent->changeDetected(paths); + const QStringList totalPaths = addCoalescedPaths(paths); + _parent->changeDetected(totalPaths); } diff --git a/src/gui/folderwatcher_mac.h b/src/gui/folderwatcher_mac.h old mode 100644 new mode 100755 index a25d89f6d..35da12c35 --- a/src/gui/folderwatcher_mac.h +++ b/src/gui/folderwatcher_mac.h @@ -37,6 +37,7 @@ public: void removePath(const QString &) {} void startWatching(); + QStringList addCoalescedPaths(const QStringList &) const; void doNotifyParent(const QStringList &); private: -- 2.30.2