diff --git a/src/inotify/mod.rs b/src/inotify/mod.rs index 88033316..daf60447 100644 --- a/src/inotify/mod.rs +++ b/src/inotify/mod.rs @@ -161,6 +161,9 @@ impl mio::Handler for INotifyHandler { if event.is_modify() { o.insert(op::WRITE); } + if event.is_close_write() { + o.insert(op::CLOSE_WRITE); + } if event.is_attrib() { o.insert(op::CHMOD); } @@ -253,7 +256,7 @@ impl INotifyHandler { } fn add_single_watch(&mut self, path: PathBuf, is_recursive: bool, watch_self: bool) -> Result<()> { - let mut flags = flags::IN_ATTRIB | flags::IN_CREATE | flags::IN_DELETE | + let mut flags = flags::IN_ATTRIB | flags::IN_CREATE | flags::IN_DELETE | flags::IN_CLOSE_WRITE | flags::IN_MODIFY | flags::IN_MOVED_FROM | flags::IN_MOVED_TO; if watch_self { diff --git a/src/lib.rs b/src/lib.rs index faf4ef17..163433dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -291,8 +291,10 @@ pub mod op { const RENAME = 0b001000, /// Written const WRITE = 0b010000, + /// Written + const CLOSE_WRITE = 0b100000, /// Directories need to be rescanned - const RESCAN = 0b100000, + const RESCAN = 0b1000000, } } } diff --git a/tests/notify.rs b/tests/notify.rs index dcd7f759..50b323e7 100644 --- a/tests/notify.rs +++ b/tests/notify.rs @@ -48,9 +48,14 @@ fn create_file() { assert_eq!(inflate_events(recv_events(&rx)), vec![ (tdir.mkpath("file1"), op::CREATE, None), ]); + } else if cfg!(target_os="windows") { + assert_eq!(recv_events(&rx), vec![ + (tdir.mkpath("file1"), op::CREATE, None) + ]); } else { assert_eq!(recv_events(&rx), vec![ (tdir.mkpath("file1"), op::CREATE, None), + (tdir.mkpath("file1"), op::CLOSE_WRITE, None) ]); } } @@ -77,9 +82,14 @@ fn write_file() { assert_eq!(inflate_events(recv_events(&rx)), vec![ (tdir.mkpath("file1"), op::CREATE | op::WRITE, None), // excessive create event ]); + } else if cfg!(target_os="windows") { + assert_eq!(recv_events(&rx), vec![ + (tdir.mkpath("file1"), op::WRITE, None) + ]); } else { assert_eq!(recv_events(&rx), vec![ (tdir.mkpath("file1"), op::WRITE, None), + (tdir.mkpath("file1"), op::CLOSE_WRITE, None) ]); } } @@ -297,8 +307,9 @@ fn create_rename_overwrite_file() { assert_eq!(cookies.len(), 1); assert_eq!(actual, vec![ (tdir.mkpath("file1a"), op::CREATE, None), + (tdir.mkpath("file1a"), op::CLOSE_WRITE, None), (tdir.mkpath("file1a"), op::RENAME, Some(cookies[0])), - (tdir.mkpath("file1b"), op::RENAME, Some(cookies[0])), + (tdir.mkpath("file1b"), op::RENAME, Some(cookies[0])) ]); } } diff --git a/tests/watcher.rs b/tests/watcher.rs index bd865996..03cca5cf 100644 --- a/tests/watcher.rs +++ b/tests/watcher.rs @@ -206,10 +206,18 @@ fn watch_recursive_create_directory() { recv_events(&rx) }; - assert_eq!(actual, vec![ - (tdir.mkpath("dir1"), op::CREATE, None), - (tdir.mkpath("dir1/file1"), op::CREATE, None) - ]); + if cfg!(target_os="linux") { + assert_eq!(actual, vec![ + (tdir.mkpath("dir1"), op::CREATE, None), + (tdir.mkpath("dir1/file1"), op::CREATE, None), + (tdir.mkpath("dir1/file1"), op::CLOSE_WRITE, None) + ]); + } else { + assert_eq!(actual, vec![ + (tdir.mkpath("dir1"), op::CREATE, None), + (tdir.mkpath("dir1/file1"), op::CREATE, None) + ]); + } } #[test] @@ -253,6 +261,17 @@ fn watch_recursive_move() { (tdir.mkpath("dir1b"), op::RENAME, Some(cookies[0])), (tdir.mkpath("dir1b/file2"), op::CREATE, None) ]); + } else if cfg!(target_os="linux") { + let cookies = extract_cookies(&actual); + assert_eq!(cookies.len(), 1); + assert_eq!(actual, vec![ + (tdir.mkpath("dir1a/file1"), op::CREATE, None), + (tdir.mkpath("dir1a/file1"), op::CLOSE_WRITE, None), + (tdir.mkpath("dir1a"), op::RENAME, Some(cookies[0])), + (tdir.mkpath("dir1b"), op::RENAME, Some(cookies[0])), + (tdir.mkpath("dir1b/file2"), op::CREATE, None), + (tdir.mkpath("dir1b/file2"), op::CLOSE_WRITE, None) + ]); } else { let cookies = extract_cookies(&actual); assert_eq!(cookies.len(), 1); @@ -383,10 +402,18 @@ fn watch_nonrecursive() { "dir2/file2", ]); - assert_eq!(recv_events(&rx), vec![ - (tdir.mkpath("dir2"), op::CREATE, None), - (tdir.mkpath("file0"), op::CREATE, None) - ]); + if cfg!(target_os="linux") { + assert_eq!(recv_events(&rx), vec![ + (tdir.mkpath("dir2"), op::CREATE, None), + (tdir.mkpath("file0"), op::CREATE, None), + (tdir.mkpath("file0"), op::CLOSE_WRITE, None) + ]); + } else { + assert_eq!(recv_events(&rx), vec![ + (tdir.mkpath("dir2"), op::CREATE, None), + (tdir.mkpath("file0"), op::CREATE, None) + ]); + } } #[test] @@ -412,6 +439,11 @@ fn watch_file() { assert_eq!(recv_events(&rx), vec![ (tdir.mkpath("file1"), op::CREATE | op::WRITE, None) // excessive write create ]); + } else if cfg!(target_os="linux") { + assert_eq!(recv_events(&rx), vec![ + (tdir.mkpath("file1"), op::WRITE, None), + (tdir.mkpath("file1"), op::CLOSE_WRITE, None) + ]); } else { assert_eq!(recv_events(&rx), vec![ (tdir.mkpath("file1"), op::WRITE, None) @@ -941,9 +973,14 @@ fn self_rename_directory() { if cfg!(target_os="macos") { // macos doesn't watch files, but paths assert_eq!(actual, vec![]); - } else { + } else if cfg!(target_os="linux") { assert_eq!(actual, vec![ (tdir.mkpath("dir1/file1"), op::CREATE, None), // path doesn't get updated + (tdir.mkpath("dir1/file1"), op::CLOSE_WRITE, None) + ]); + } else { + assert_eq!(actual, vec![ + (tdir.mkpath("dir1/file1"), op::CREATE, None) // path doesn't get updated ]); } @@ -1012,9 +1049,14 @@ fn parent_rename_file() { if cfg!(target_os="macos") { // macos doesn't watch files, but paths assert_eq!(actual, vec![]); - } else { + } else if cfg!(target_os="linux") { assert_eq!(actual, vec![ (tdir.mkpath("dir1/file1"), op::WRITE, None), // path doesn't get updated + (tdir.mkpath("dir1/file1"), op::CLOSE_WRITE, None) + ]); + } else { + assert_eq!(actual, vec![ + (tdir.mkpath("dir1/file1"), op::WRITE, None) // path doesn't get updated ]); }