|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+use std::io;
|
|
|
2
|
+use std::pin::Pin;
|
|
|
3
|
+use std::task::{Context, Poll};
|
|
|
4
|
+use std::time::Duration;
|
|
|
5
|
+
|
|
|
6
|
+use futures::stream::Stream;
|
|
|
7
|
+
|
|
|
8
|
+/// A stream which delays inotify events and combines them whenever possible.
|
|
|
9
|
+///
|
|
|
10
|
+/// The type tries to reduce the number of unnecessary events (e.g., a file which was created and
|
|
|
11
|
+/// then immediately removed again, or a large number of modification events for the same file) and
|
|
|
12
|
+/// tries to reconstruct additional information (e.g., if a file was moved from one directory to
|
|
|
13
|
+/// another, in which case inotify cannot detect the move).
|
|
|
14
|
+pub struct FileEventDelay<T>
|
|
|
15
|
+where
|
|
|
16
|
+ T: Stream<Item = io::Result<inotify::EventOwned>>,
|
|
|
17
|
+{
|
|
|
18
|
+ input: T,
|
|
|
19
|
+ min_delay: Duration,
|
|
|
20
|
+}
|
|
|
21
|
+
|
|
|
22
|
+impl<T> FileEventDelay<T>
|
|
|
23
|
+where
|
|
|
24
|
+ T: Stream<Item = io::Result<inotify::EventOwned>>,
|
|
|
25
|
+{
|
|
|
26
|
+ pub fn new(input: T, min_delay: Duration) -> Self {
|
|
|
27
|
+ Self { input, min_delay }
|
|
|
28
|
+ }
|
|
|
29
|
+}
|
|
|
30
|
+
|
|
|
31
|
+impl<T> Stream for FileEventDelay<T>
|
|
|
32
|
+where
|
|
|
33
|
+ T: Stream<Item = io::Result<inotify::EventOwned>>,
|
|
|
34
|
+{
|
|
|
35
|
+ type Item = io::Result<FileEvent>;
|
|
|
36
|
+
|
|
|
37
|
+ fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
|
|
38
|
+ // TODO: Two arrays, fill one array with inotify events. Whenever a periodic timer elapses,
|
|
|
39
|
+ // parse contents of the other array and clear it, and swap the two arrays.
|
|
|
40
|
+ // TODO
|
|
|
41
|
+ panic!("Not yet implemented.");
|
|
|
42
|
+ }
|
|
|
43
|
+}
|
|
|
44
|
+
|
|
|
45
|
+pub enum FileEvent {
|
|
|
46
|
+ // TODO
|
|
|
47
|
+}
|