Fix missing subdirectory discovery on move operations in macOS.
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Wed, 16 Sep 2020 17:50:16 +0000 (19:50 +0200)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Thu, 17 Sep 2020 13:44:32 +0000 (15:44 +0200)
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 [changed mode: 0644->0755]
src/gui/folderwatcher_mac.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 3fa10f7..ee23141
@@ -19,6 +19,7 @@
 
 
 #include <cerrno>
+#include <QDirIterator>
 #include <QStringList>
 
 
@@ -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);
 }
 
 
old mode 100644 (file)
new mode 100755 (executable)
index a25d89f..35da12c
@@ -37,6 +37,7 @@ public:
     void removePath(const QString &) {}
 
     void startWatching();
+    QStringList addCoalescedPaths(const QStringList &) const;
     void doNotifyParent(const QStringList &);
 
 private: