From a9066e2d0c3134de9f64a347d2de362a82e39f6a Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Thu, 23 Sep 2021 13:34:20 +0200 Subject: [PATCH] tail: switch from Notify 4.0.17 to 5.0.0-pre.13 * treat input filenames as PathBuf instead of String --- Cargo.lock | 149 +++++++++------------------------------- src/uu/tail/Cargo.toml | 2 +- src/uu/tail/src/tail.rs | 37 +++++----- 3 files changed, 52 insertions(+), 136 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7eaaa4bec..3d0c2d135 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -582,7 +582,7 @@ dependencies = [ "bitflags", "crossterm_winapi", "libc", - "mio 0.7.7", + "mio", "parking_lot", "signal-hook", "signal-hook-mio", @@ -783,21 +783,11 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" -[[package]] -name = "fsevent" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" -dependencies = [ - "bitflags", - "fsevent-sys", -] - [[package]] name = "fsevent-sys" -version = "2.0.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" +checksum = "5c0e564d24da983c053beff1bb7178e237501206840a3e6bf4e267b9e8ae734a" dependencies = [ "libc", ] @@ -818,22 +808,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "funty" version = "1.1.0" @@ -970,9 +944,9 @@ checksum = "46dbcb333e86939721589d25a3557e180b52778cb33c7fdfe9e0158ff790d5ec" [[package]] name = "inotify" -version = "0.7.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" +checksum = "d88ed757e516714cd8736e65b84ed901f72458512111871f20c1d377abdfbf5e" dependencies = [ "bitflags", "inotify-sys", @@ -1003,15 +977,6 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c429fffa658f288669529fc26565f728489a2e39bc7b24a428aaaf51355182e" -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "itertools" version = "0.8.2" @@ -1040,6 +1005,26 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "kqueue" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058a107a784f8be94c7d35c1300f4facced2e93d2fbe5b1452b44e905ddca4a9" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587" +dependencies = [ + "bitflags", + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1137,25 +1122,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.2", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.7.7" @@ -1164,35 +1130,11 @@ checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" dependencies = [ "libc", "log", - "miow 0.3.7", + "miow", "ntapi", "winapi 0.3.9", ] -[[package]] -name = "mio-extras" -version = "2.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" -dependencies = [ - "lazycell", - "log", - "mio 0.6.23", - "slab", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - [[package]] name = "miow" version = "0.3.7" @@ -1202,17 +1144,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "nix" version = "0.19.1" @@ -1270,18 +1201,18 @@ dependencies = [ [[package]] name = "notify" -version = "4.0.17" +version = "5.0.0-pre.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" +checksum = "245d358380e2352c2d020e8ee62baac09b3420f1f6c012a31326cfced4ad487d" dependencies = [ "bitflags", + "crossbeam-channel", "filetime", - "fsevent", "fsevent-sys", "inotify", + "kqueue", "libc", - "mio 0.6.23", - "mio-extras", + "mio", "walkdir", "winapi 0.3.9", ] @@ -1965,7 +1896,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29fd5867f1c4f2c5be079aee7a2adf1152ebb04a4bc4d341f504b7dece607ed4" dependencies = [ "libc", - "mio 0.7.7", + "mio", "signal-hook", ] @@ -1978,12 +1909,6 @@ dependencies = [ "libc", ] -[[package]] -name = "slab" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" - [[package]] name = "smallvec" version = "0.6.14" @@ -3514,16 +3439,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "wyz" version = "0.2.0" diff --git a/src/uu/tail/Cargo.toml b/src/uu/tail/Cargo.toml index 0565ec72f..a6267f942 100644 --- a/src/uu/tail/Cargo.toml +++ b/src/uu/tail/Cargo.toml @@ -16,7 +16,7 @@ path = "src/tail.rs" [dependencies] clap = { version = "2.33", features = ["wrap_help"] } -notify = "4.0.17" +notify = "5.0.0-pre.13" libc = "0.2.42" uucore = { version=">=0.0.9", package="uucore", path="../../uucore", features=["ringbuffer"] } uucore_procs = { version=">=0.0.6", package="uucore_procs", path="../../uucore_procs" } diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index a7cab6d19..1444f556e 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -24,7 +24,7 @@ use std::collections::VecDeque; use std::fmt; use std::fs::{File, Metadata}; use std::io::{stdin, stdout, BufRead, BufReader, Read, Seek, SeekFrom, Write}; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::sync::mpsc::channel; use std::time::Duration; use uucore::display::Quotable; @@ -152,20 +152,20 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let verbose = matches.is_present(options::verbosity::VERBOSE); let quiet = matches.is_present(options::verbosity::QUIET); - let files: Vec = matches + let paths: Vec = matches .values_of(options::ARG_FILES) - .map(|v| v.map(ToString::to_string).collect()) - .unwrap_or_else(|| vec![String::from("-")]); + .map(|v| v.map(PathBuf::from).collect()) + .unwrap_or_else(|| vec![PathBuf::from("-")]); - let mut files_count = files.len(); + let mut files_count = paths.len(); let mut first_header = true; - let mut readers: Vec<(Box, &String)> = Vec::new(); + let mut readers: Vec<(Box, &PathBuf)> = Vec::new(); #[cfg(unix)] - let stdin_string = String::from("standard input"); + let stdin_string = PathBuf::from("standard input"); - for filename in &files { - let use_stdin = filename.as_str() == "-"; + for filename in &paths { + let use_stdin = filename.to_str() == Some("-"); if use_stdin { if verbose && !quiet { @@ -211,7 +211,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if !first_header { println!(); } - println!("==> {} <==", filename); + println!("==> {} <==", filename.display()); } first_header = false; let mut file = File::open(&path).unwrap(); @@ -315,7 +315,7 @@ pub fn uu_app() -> App<'static, 'static> { ) } -fn follow(readers: &mut [(T, &String)], settings: &Settings) { +fn follow(readers: &mut [(T, &PathBuf)], settings: &Settings) { assert!(settings.follow); if readers.is_empty() { return; @@ -325,16 +325,17 @@ fn follow(readers: &mut [(T, &String)], settings: &Settings) { let mut read_some = false; let mut process = platform::ProcessChecker::new(settings.pid); - use notify::{PollWatcher, RecursiveMode, Watcher}; + use notify::{RecursiveMode, Watcher}; + use std::sync::{Arc, Mutex}; let (tx, rx) = channel(); - let mut watcher; + let mut watcher: Box; if dbg!(settings.force_polling) { - watcher = PollWatcher::new(tx, settings.sleep_sec).unwrap(); + watcher = Box::new( + notify::PollWatcher::with_delay(Arc::new(Mutex::new(tx)), settings.sleep_sec).unwrap(), + ); } else { - // The trait `Watcher` cannot be made into an object because it requires `Self: Sized`. - // watcher = watcher(tx, setting.sleep_sec).unwrap(); - todo!(); + watcher = Box::new(notify::RecommendedWatcher::new(tx).unwrap()); }; for (_, path) in readers.iter() { @@ -362,7 +363,7 @@ fn follow(readers: &mut [(T, &String)], settings: &Settings) { Ok(_) => { read_some = true; if i != last { - println!("\n==> {} <==", filename); + println!("\n==> {} <==", filename.display()); last = i; } print!("{}", datum);