OS X: White-list the folder watcher enums
authorMarkus Goetz <markus@woboq.com>
Thu, 2 Jun 2016 16:12:47 +0000 (18:12 +0200)
committerMarkus Goetz <markus@woboq.com>
Thu, 2 Jun 2016 16:20:07 +0000 (18:20 +0200)
I got syncs triggered for even opening a file by double clicking it in Finder
and having launched Preview.app (e.g. for JPEG files).

src/gui/folderwatcher_mac.cpp

index ada7f106440fde261ca14a03963678fdd126f951..be426084219f7b9526f751c5b132d455f0bc6bc9 100644 (file)
@@ -51,6 +51,14 @@ static void callback(
     Q_UNUSED(eventFlags)
     Q_UNUSED(eventIds)
 
+    const FSEventStreamEventFlags c_interestingFlags
+            = kFSEventStreamEventFlagItemCreated // for new folder/file
+            | kFSEventStreamEventFlagItemRemoved // for rm
+            | kFSEventStreamEventFlagItemInodeMetaMod // for mtime change
+            | kFSEventStreamEventFlagItemRenamed // also coming for moves to trash in finder
+            | kFSEventStreamEventFlagItemModified; // for content change
+    //We ignore other flags, e.g. for owner change, xattr change, Finder label change etc
+
     qDebug() << "FolderWatcherPrivate::callback by OS X";
 
     QStringList paths;
@@ -62,8 +70,14 @@ static void callback(
         CFIndex pathLength = CFStringGetLength(path);
         qstring.resize(pathLength);
         CFStringGetCharacters(path, CFRangeMake(0, pathLength), reinterpret_cast<UniChar *>(qstring.data()));
+        QString fn = qstring.normalized(QString::NormalizationForm_C);
+
+        if (!(eventFlags[i] & c_interestingFlags)) {
+            qDebug() << "Ignoring non-content changes for" << fn;
+            continue;
+        }
 
-        paths.append(qstring.normalized(QString::NormalizationForm_C));
+        paths.append(fn);
     }
 
     reinterpret_cast<FolderWatcherPrivate*>(clientCallBackInfo)->doNotifyParent(paths);