]> gitweb.factorcode.org Git - factor.git/commitdiff
io.monitors.macosx: enable per-file monitoring.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 31 Dec 2021 03:37:12 +0000 (19:37 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 31 Dec 2021 03:37:12 +0000 (19:37 -0800)
basis/io/monitors/macosx/macosx.factor

index 75211a06b1f83dbd00a4ce3f638e4efce43d57cf..e22b3dbd9998cb72ef9deb0ae1a1da3b763399b2 100644 (file)
@@ -1,19 +1,27 @@
 ! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays core-foundation.fsevents destructors fry
-io.backend io.monitors kernel locals sequences system ;
+USING: accessors arrays combinators core-foundation.fsevents
+destructors io.backend io.monitors kernel math sequences system
+;
 IN: io.monitors.macosx
 
 TUPLE: macosx-monitor < monitor handle ;
 
 : enqueue-notifications ( triples monitor -- )
-    '[ first { +modify-file+ } _ queue-change ] each ;
+    '[
+        first2 V{ } clone swap {
+            [ kFSEventStreamEventFlagItemCreated bitand zero? [ +add-file+ suffix! ] unless ]
+            [ kFSEventStreamEventFlagItemRemoved bitand zero? [ +remove-file+ suffix! ] unless ]
+            [ kFSEventStreamEventFlagItemRenamed bitand zero? [ +rename-file+ suffix! ] unless ]
+            [ kFSEventStreamEventFlagItemModified bitand zero? [ +modify-file+ suffix! ] unless ]
+        } cleave [ { +modify-file+ } ] [ >array ] if-empty _ queue-change
+    ] each ;
 
 M:: macosx (monitor) ( path recursive? mailbox -- monitor )
     path normalize-path :> path
     path mailbox macosx-monitor new-monitor
     dup [ enqueue-notifications ] curry
-    path 1array 0 0 <event-stream> >>handle ;
+    path 1array 0 kFSEventStreamCreateFlagFileEvents <event-stream> >>handle ;
 
 M: macosx-monitor dispose*
     [ handle>> dispose ] [ call-next-method ] bi ;