@@ -132,9 +132,12 @@ pub fn start_watcher(
132132
133133/// Check whether a filesystem event is relevant (i.e., a .jsonl file from another device).
134134fn is_relevant_event ( event : & Event , my_device_id : & str ) -> bool {
135- // Only care about creates, modifications, and renames
135+ // Only care about creates (new oplog files) and close-write events.
136+ // Skip Modify events to avoid reading partially-written files.
136137 match event. kind {
137- EventKind :: Create ( _) | EventKind :: Modify ( _) => { }
138+ EventKind :: Create ( _) => { }
139+ EventKind :: Modify ( notify:: event:: ModifyKind :: Data ( _) ) => { }
140+ EventKind :: Access ( notify:: event:: AccessKind :: Close ( notify:: event:: AccessMode :: Write ) ) => { }
138141 _ => return false ,
139142 }
140143
@@ -147,10 +150,18 @@ fn is_relevant_event(event: &Event, my_device_id: &str) -> bool {
147150 return false ;
148151 }
149152
150- // Check that the file is NOT in our own device subfolder
151- let path_str = path. to_string_lossy ( ) ;
152- !path_str. contains ( & format ! ( "/{}/" , my_device_id) )
153- && !path_str. contains ( & format ! ( "\\ {}\\ " , my_device_id) )
153+ // Only ignore events from the immediate `devices/{my_device_id}/` subfolder.
154+ // Check the path component right after "devices/" — not any arbitrary component.
155+ let components: Vec < _ > = path. components ( )
156+ . map ( |c| c. as_os_str ( ) . to_string_lossy ( ) . to_string ( ) )
157+ . collect ( ) ;
158+ let devices_idx = components. iter ( ) . position ( |c| c == "devices" ) ;
159+ if let Some ( idx) = devices_idx {
160+ if let Some ( device_dir) = components. get ( idx + 1 ) {
161+ return device_dir != my_device_id;
162+ }
163+ }
164+ true // no "devices/" in path — allow event
154165 } )
155166}
156167
0 commit comments