@@ -26,6 +26,7 @@ struct ScheduleWorker {
2626 tx : mpsc:: Sender < DebouncedEvent > ,
2727 operations_buffer : OperationsBuffer ,
2828 stopped : Arc < AtomicBool > ,
29+ worker_ongoing_write_event : Arc < Mutex < Option < ( Instant , PathBuf ) > > > ,
2930}
3031
3132impl ScheduleWorker {
@@ -56,7 +57,12 @@ impl ScheduleWorker {
5657 }
5758 let message = match op {
5859 Some ( op:: Op :: CREATE ) => Some ( DebouncedEvent :: Create ( path) ) ,
59- Some ( op:: Op :: WRITE ) => Some ( DebouncedEvent :: Write ( path) ) ,
60+ Some ( op:: Op :: WRITE ) => {
61+ //disable ongoing_write
62+ let mut ongoing_write_event = self . worker_ongoing_write_event . lock ( ) . unwrap ( ) ;
63+ * ongoing_write_event = None ;
64+ Some ( DebouncedEvent :: Write ( path) )
65+ } ,
6066 Some ( op:: Op :: CHMOD ) => Some ( DebouncedEvent :: Chmod ( path) ) ,
6167 Some ( op:: Op :: REMOVE ) => Some ( DebouncedEvent :: Remove ( path) ) ,
6268 Some ( op:: Op :: RENAME ) if is_partial_rename => {
@@ -116,6 +122,8 @@ pub struct WatchTimer {
116122 delay : Duration ,
117123 events : Arc < Mutex < VecDeque < ScheduledEvent > > > ,
118124 stopped : Arc < AtomicBool > ,
125+ pub ongoing_write_event : Arc < Mutex < Option < ( Instant , PathBuf ) > > > ,
126+ pub ongoing_write_duration : Option < Duration > ,
119127}
120128
121129impl WatchTimer {
@@ -133,6 +141,8 @@ impl WatchTimer {
133141 let worker_stop_trigger = stop_trigger. clone ( ) ;
134142 let worker_events = events. clone ( ) ;
135143 let worker_stopped = stopped. clone ( ) ;
144+ let ongoing_write_event = Arc :: new ( Mutex :: new ( None ) ) ;
145+ let worker_ongoing_write_event = ongoing_write_event. clone ( ) ;
136146 thread:: spawn ( move || {
137147 ScheduleWorker {
138148 new_event_trigger : worker_new_event_trigger,
@@ -141,6 +151,7 @@ impl WatchTimer {
141151 tx,
142152 operations_buffer,
143153 stopped : worker_stopped,
154+ worker_ongoing_write_event,
144155 }
145156 . run ( ) ;
146157 } ) ;
@@ -152,9 +163,15 @@ impl WatchTimer {
152163 delay,
153164 events,
154165 stopped,
166+ ongoing_write_event,
167+ ongoing_write_duration : None ,
155168 }
156169 }
157170
171+ pub fn set_ongoing_write_duration ( & mut self , duration : Option < Duration > ) {
172+ self . ongoing_write_duration = duration;
173+ }
174+
158175 pub fn schedule ( & mut self , path : PathBuf ) -> u64 {
159176 self . counter = self . counter . wrapping_add ( 1 ) ;
160177
0 commit comments