1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
//! Cross-platform file system notification library
//!
//! Source is on GitHub: https://github.com/notify-rs/notify
//!
//! # Installation
//!
//! ```toml
//! [dependencies]
//! notify = "4.0.12"
//! ```
//!
//! # Examples
//!
//! Notify provides two APIs. The default API _debounces_ events (if the backend reports two
//! similar events in close succession, Notify will only report one). The raw API emits file
//! changes as soon as they happen. For more details, see
//! [`Watcher::new_raw`](trait.Watcher.html#tymethod.new_raw) and
//! [`Watcher::new`](trait.Watcher.html#tymethod.new).
//!
//! ## Default (debounced) API
//!
//! ```no_run
//! extern crate notify;
//!
//! use notify::{Watcher, RecursiveMode, watcher};
//! use std::sync::mpsc::channel;
//! use std::time::Duration;
//!
//! fn main() {
//! // Create a channel to receive the events.
//! let (tx, rx) = channel();
//!
//! // Create a watcher object, delivering debounced events.
//! // The notification back-end is selected based on the platform.
//! let mut watcher = watcher(tx, Duration::from_secs(10)).unwrap();
//!
//! // Add a path to be watched. All files and directories at that path and
//! // below will be monitored for changes.
//! watcher.watch("/home/test/notify", RecursiveMode::Recursive).unwrap();
//!
//! loop {
//! match rx.recv() {
//! Ok(event) => println!("{:?}", event),
//! Err(e) => println!("watch error: {:?}", e),
//! }
//! }
//! }
//! ```
//!
//! Using the default API is easy, all possible events are described in the
//! [`DebouncedEvent`](enum.DebouncedEvent.html) documentation. But in order to understand the
//! subtleties of the event delivery, you should read the [`op`](op/index.html) documentation as
//! well.
//!
//! ## Raw API
//!
//! ```no_run
//! extern crate notify;
//!
//! use notify::{Watcher, RecursiveMode, RawEvent, raw_watcher};
//! use std::sync::mpsc::channel;
//!
//! fn main() {
//! // Create a channel to receive the events.
//! let (tx, rx) = channel();
//!
//! // Create a watcher object, delivering raw events.
//! // The notification back-end is selected based on the platform.
//! let mut watcher = raw_watcher(tx).unwrap();
//!
//! // Add a path to be watched. All files and directories at that path and
//! // below will be monitored for changes.
//! watcher.watch("/home/test/notify", RecursiveMode::Recursive).unwrap();
//!
//! loop {
//! match rx.recv() {
//! Ok(RawEvent{path: Some(path), op: Ok(op), cookie}) => {
//! println!("{:?} {:?} ({:?})", op, path, cookie)
//! },
//! Ok(event) => println!("broken event: {:?}", event),
//! Err(e) => println!("watch error: {:?}", e),
//! }
//! }
//! }
//! ```
//!
//! The event structure is described in the [`RawEvent`](struct.RawEvent.html) documentation,
//! all possible operations delivered in an event are described in the [`op`](op/index.html)
//! documentation.
extern crate bitflags;
extern crate filetime;
extern crate fsevent_sys;
extern crate libc;
extern crate mio;
extern crate mio_extras;
extern crate winapi;
pub use Op;
use AsRef;
use Error as StdError;
use fmt;
use io;
use ;
use Result as StdResult;
use Sender;
use Duration;
pub use FsEventWatcher;
pub use INotifyWatcher;
pub use NullWatcher;
pub use PollWatcher;
pub use ReadDirectoryChangesWatcher;
/// Contains the `Op` type which describes the actions for an event.
///
/// `notify` aims to provide unified behavior across platforms. This however is not always possible
/// due to the underlying technology of the various operating systems. So there are some issues
/// `notify`-API users will have to take care of themselves, depending on their needs.
///
///
/// # Chmod
///
/// __Linux, macOS__
///
/// On Linux and macOS the `CHMOD` event is emitted whenever attributes or extended attributes
/// change.
///
/// __Windows__
///
/// On Windows a `WRITE` event is emitted when attributes change. This makes it impossible to
/// distinguish between writes to a file or its meta data.
///
///
/// # Close-Write
///
/// A `CLOSE_WRITE` event is emitted whenever a file that was opened for writing has been closed.
///
/// __This event is only available on Linux__.
///
///
/// # Create
///
/// A `CREATE` event is emitted whenever a new file or directory is created.
///
/// Upon receiving a `Create` event for a directory, it is necessary to scan the newly created
/// directory for contents. The directory can contain files or directories if those contents were
/// created before the directory could be watched, or if the directory was moved into the watched
/// directory.
///
/// # Remove
///
/// ## Remove file or directory within a watched directory
///
/// A `REMOVE` event is emitted whenever a file or directory is removed.
///
/// ## Remove watched file or directory itself
///
/// With the exception of Windows a `REMOVE` event is emitted whenever the watched file or
/// directory itself is removed. The behavior after the remove differs between platforms though.
///
/// __Linux__
///
/// When a watched file or directory is removed, its watch gets destroyed and no new events will be
/// sent.
///
/// __Windows__
///
/// If a watched directory is removed, an empty event is emitted.
///
/// When watching a single file on Windows, the file path will continue to be watched until either
/// the watch is removed by the API user or the parent directory gets removed.
///
/// When watching a directory on Windows, the watch will get destroyed and no new events will be
/// sent.
///
/// __macOS__
///
/// While Linux and Windows monitor "inodes", macOS monitors "paths". So a watch stays active even
/// after the watched file or directory has been removed and it will emit events in case a new file
/// or directory is created in its place.
///
///
/// # Rename
///
/// A `RENAME` event is emitted whenever a file or directory has been renamed or moved to a
/// different directory.
///
/// ## Rename file or directory within a watched directory
///
/// __Linux, Windows__
///
/// A rename with both the source and the destination path inside a watched directory produces two
/// `RENAME` events. The first event contains the source path, the second contains the destination
/// path. Both events share the same cookie.
///
/// A rename that originates inside of a watched directory but ends outside of a watched directory
/// produces a `DELETE` event.
///
/// A rename that originates outside of a watched directory and ends inside of a watched directory
/// produces a `CREATE` event.
///
/// __macOS__
///
/// A `RENAME` event is produced whenever a file or directory is moved. This includes moves within
/// the watched directory as well as moves into or out of the watched directory. It is up to the
/// API user to determine what exactly happened. Usually when a move within a watched directory
/// occurs, the cookie is set for both connected events. This can however fail eg. if a file gets
/// renamed multiple times without a delay (test `fsevents_rename_rename_file_0`). So in some cases
/// rename cannot be caught properly but would be interpreted as a sequence of events where a file
/// or directory is moved out of the watched directory and a different file or directory is moved
/// in.
///
/// ## Rename watched file or directory itself
///
/// With the exception of Windows a `RENAME` event is emitted whenever the watched file or
/// directory itself is renamed. The behavior after the rename differs between platforms though.
/// Depending on the platform either the moved file or directory will continue to be watched or the
/// old path. If the moved file or directory will continue to be watched, the paths of emitted
/// events will still be prefixed with the old path though.
///
/// __Linux__
///
/// Linux will continue to watch the moved file or directory. Events will contain paths prefixed
/// with the old path.
///
/// __Windows__
///
/// Currently there is no event emitted when a watched directory is renamed. But the directory will
/// continue to be watched and events will contain paths prefixed with the old path.
///
/// When renaming a watched file, a `RENAME` event is emitted but the old path will continue to be
/// watched.
///
/// __macOS__
///
/// macOS will continue to watch the (now non-existing) path.
///
/// ## Rename parent directory of watched file or directory
///
/// Currently no event will be emitted when any parent directory of the watched file or directory
/// is renamed. Depending on the platform either the moved file or directory will continue to be
/// watched or the old path. If the moved file or directory will continue to be watched, the paths
/// of emitted events will still be prefixed with the old path though.
///
/// __Linux, Windows__
///
/// Linux and Windows will continue to watch the moved file or directory. Events will contain paths
/// prefixed with the old path.
///
/// __macOS__
///
/// macOS will continue to watch the (now non-existing) path.
///
///
/// # Rescan
///
/// A `RESCAN` event indicates that an error occurred and the watched directories need to be
/// rescanned. This can happen if the internal event queue has overflown and some events were
/// dropped. Or with FSEvents if events were coalesced hierarchically.
///
/// __Windows__
///
/// At the moment `RESCAN` events aren't emitted on Windows.
///
/// __Queue size__
///
/// Linux: `/proc/sys/fs/inotify/max_queued_events`
///
/// Windows: 16384 Bytes. The actual amount of events that fit into the queue depends on the length
/// of the paths.
///
///
/// # Write
///
/// A `WRITE` event is emitted whenever a file has been written to.
///
/// __Windows__
///
/// On Windows a `WRITE` event is emitted when attributes change.
/// Event delivered when action occurs on a watched path in _raw_ mode
unsafe
/// Event delivered when action occurs on a watched path in debounced mode
/// Errors generated from the `notify` crate
/// Type alias to use this library's `Error` type in a Result
pub type Result<T> = ;
/// Indicates whether only the provided directory or its sub-directories as well should be watched
/// Type that can deliver file activity notifications
///
/// Watcher is implemented per platform using the best implementation available on that platform.
/// In addition to such event driven implementations, a polling implementation is also provided
/// that should work on any platform.
/// The recommended `Watcher` implementation for the current platform
pub type RecommendedWatcher = INotifyWatcher;
/// The recommended `Watcher` implementation for the current platform
pub type RecommendedWatcher = FsEventWatcher;
/// The recommended `Watcher` implementation for the current platform
pub type RecommendedWatcher = ReadDirectoryChangesWatcher;
/// The recommended `Watcher` implementation for the current platform
pub type RecommendedWatcher = PollWatcher;
/// Convenience method for creating the `RecommendedWatcher` for the current platform in _raw_ mode.
///
/// See [`Watcher::new_raw`](trait.Watcher.html#tymethod.new_raw).
/// Convenience method for creating the `RecommendedWatcher` for the current
/// platform in default (debounced) mode.
///
/// See [`Watcher::new`](trait.Watcher.html#tymethod.new).