| 6 | |
| 7 | #[test] |
| 8 | fn test_inotify_iter() { |
| 9 | let inotify = inotify::init(CreateFlags::NONBLOCK).unwrap(); |
| 10 | create_dir_all("/tmp/.rustix-inotify-test").unwrap(); |
| 11 | inotify::add_watch( |
| 12 | &inotify, |
| 13 | "/tmp/.rustix-inotify-test", |
| 14 | WatchFlags::ALL_EVENTS, |
| 15 | ) |
| 16 | .unwrap(); |
| 17 | |
| 18 | File::create("/tmp/.rustix-inotify-test/foo").unwrap(); |
| 19 | rename( |
| 20 | "/tmp/.rustix-inotify-test/foo", |
| 21 | "/tmp/.rustix-inotify-test/bar", |
| 22 | ) |
| 23 | .unwrap(); |
| 24 | remove_file("/tmp/.rustix-inotify-test/bar").unwrap(); |
| 25 | |
| 26 | let mut output = String::new(); |
| 27 | let mut cookie = 0; |
| 28 | |
| 29 | let mut buf = [MaybeUninit::uninit(); 512]; |
| 30 | let mut iter = inotify::Reader::new(inotify, &mut buf); |
| 31 | loop { |
| 32 | let e = match iter.next() { |
| 33 | Err(Errno::WOULDBLOCK) => break, |
| 34 | r => r.unwrap(), |
| 35 | }; |
| 36 | |
| 37 | writeln!(output, "{e:#?}").unwrap(); |
| 38 | if e.cookie() != 0 { |
| 39 | cookie = e.cookie(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | let expected = format!( |
| 44 | r#"Event {{ |
| 45 | wd: 1, |
| 46 | events: ReadFlags( |
| 47 | CREATE, |
| 48 | ), |
| 49 | cookie: 0, |
| 50 | file_name: Some( |
| 51 | "foo", |
| 52 | ), |
| 53 | }} |
| 54 | Event {{ |
| 55 | wd: 1, |
| 56 | events: ReadFlags( |
| 57 | OPEN, |
| 58 | ), |
| 59 | cookie: 0, |
| 60 | file_name: Some( |
| 61 | "foo", |
| 62 | ), |
| 63 | }} |
| 64 | Event {{ |
| 65 | wd: 1, |