diff --git a/notify-types/Cargo.toml b/notify-types/Cargo.toml index 7b63de71..ab826c0e 100644 --- a/notify-types/Cargo.toml +++ b/notify-types/Cargo.toml @@ -19,10 +19,10 @@ serialization-compat-6 = [] [dependencies] instant = "0.1.12" -serde = { version = "1.0.89", features = ["derive"], optional = true } -mock_instant = { version = "0.3.0", optional = true } +serde = { version = "1.0.201", features = ["derive"], optional = true } +mock_instant = { version = "0.4.0", optional = true } [dev-dependencies] -serde_json = "1.0.39" -insta = "1.34.0" -rstest = "0.17.0" +erde_json = "1.0.117" +insta = "1.38.0" +rstest = "0.19.0" diff --git a/notify/Cargo.toml b/notify/Cargo.toml index 8730d7fd..4f65e042 100644 --- a/notify/Cargo.toml +++ b/notify/Cargo.toml @@ -20,11 +20,11 @@ edition = "2021" [dependencies] notify-types = { version = "1.0.0", path = "../notify-types" } -crossbeam-channel = { version = "0.5.0", optional = true } -filetime = "0.2.22" -libc = "0.2.4" -log = "0.4.17" -walkdir = "2.2.2" +crossbeam-channel = { version = "0.5.12", optional = true } +filetime = "0.2.23" +libc = "0.2.154" +log = "0.4.21" +walkdir = "2.5.0" [target.'cfg(any(target_os="linux", target_os="android"))'.dependencies] inotify = { version = "0.10", default-features = false } @@ -37,18 +37,18 @@ kqueue = { version = "1.0", optional = true } mio = { version = "0.8", features = ["os-ext"], optional = true } [target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.48.0", features = ["Win32_System_Threading", "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_Security", "Win32_System_WindowsProgramming", "Win32_System_IO"] } +windows-sys = { version = "0.52.0", features = ["Win32_System_Threading", "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_Security", "Win32_System_WindowsProgramming", "Win32_System_IO"] } [target.'cfg(any(target_os="freebsd", target_os="openbsd", target_os = "netbsd", target_os = "dragonflybsd", target_os = "ios"))'.dependencies] kqueue = "^1.0.4" # fix for #344 mio = { version = "0.8", features = ["os-ext"] } [dev-dependencies] -serde_json = "1.0.39" -tempfile = "3.2.0" -nix = "0.23.1" -insta = "1.34.0" -rstest = "0.17.0" +serde_json = "1.0.117" +tempfile = "3.10.1" +nix = "0.28.0" +insta = "1.38.0" +rstest = "0.19.0" [features] default = ["macos_fsevent","crossbeam-channel"] diff --git a/notify/src/poll.rs b/notify/src/poll.rs index 9a9a9e17..1d407fe6 100644 --- a/notify/src/poll.rs +++ b/notify/src/poll.rs @@ -132,8 +132,8 @@ mod data { } /// Create [`PathData`]. - fn build_path_data(&self, meta_path: &MetaPath) -> PathData { - PathData::new(self, meta_path) + fn build_path_data(&self, meta_path: &MetaPath, file_type: &fs::FileType) -> PathData { + PathData::new(self, meta_path, file_type) } } @@ -189,6 +189,9 @@ mod data { let all_path_data = Self::scan_all_path_data(data_builder, root.clone(), is_recursive, true).collect(); + let close_initial_scan_evt = Event::new(EventKind::Other).set_info(&format!("initial_scan_complete")); + data_builder.emitter.emit(Ok(close_initial_scan_evt)); + Some(Self { root, is_recursive, @@ -283,6 +286,7 @@ mod data { }) .filter_map(move |entry| match entry.metadata() { Ok(metadata) => { + let file_type = entry.file_type(); let path = entry.into_path(); if is_initial { // emit initial scans @@ -290,8 +294,9 @@ mod data { emitter.borrow_mut().handle_event(Ok(path.clone())); } } + let meta_path = MetaPath::from_parts_unchecked(path, metadata); - let data_path = data_builder.build_path_data(&meta_path); + let data_path = data_builder.build_path_data(&meta_path, &file_type); Some((meta_path.into_path(), data_path)) } @@ -328,11 +333,14 @@ mod data { /// Checked time. last_check: Instant, + + // Type of object + path_type: fs::FileType, } impl PathData { /// Create a new `PathData`. - fn new(data_builder: &DataBuilder, meta_path: &MetaPath) -> PathData { + fn new(data_builder: &DataBuilder, meta_path: &MetaPath, file_type: &fs::FileType) -> PathData { let metadata = meta_path.metadata(); PathData { @@ -346,6 +354,7 @@ mod data { }), last_check: data_builder.now, + path_type: *file_type, } } @@ -390,8 +399,30 @@ mod data { None } } - (None, Some(_new)) => Some(EventKind::Create(CreateKind::Any)), - (Some(_old), None) => Some(EventKind::Remove(RemoveKind::Any)), + (None, Some(_new)) => { + + if _new.path_type.is_dir() { + Some(EventKind::Create(CreateKind::Folder)) + } + else if _new.path_type.is_file() { + Some(EventKind::Create(CreateKind::File)) + } + else { + Some(EventKind::Create(CreateKind::Any)) + } + }, + (Some(_old), None) => { + + if _old.path_type.is_dir() { + Some(EventKind::Remove(RemoveKind::Folder)) + } + else if _old.path_type.is_file() { + Some(EventKind::Remove(RemoveKind::File)) + } + else { + Some(EventKind::Remove(RemoveKind::Any)) + } + }, (None, None) => None, } .map(|event_kind| Event::new(event_kind).add_path(path.into()))