From 28da3f39548ef23ffdd0c802fbcf63a25bd4dfc2 Mon Sep 17 00:00:00 2001 From: Joining7943 <111500881+Joining7943@users.noreply.github.com> Date: Fri, 9 Sep 2022 23:53:17 +0200 Subject: [PATCH 1/2] tail: Do not panic in path.is_tailable() check, but return false instead --- src/uu/tail/src/tail.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index d8442f09b5a..d4f9c8a4e7f 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -1650,8 +1650,9 @@ impl PathExtTail for Path { /// Return true if `path` is is a file type that can be tailed fn is_tailable(&self) -> bool { - self.is_file() || self.exists() && self.metadata().unwrap().is_tailable() + self.is_file() || self.exists() && self.metadata().map_or(false, |meta| meta.is_tailable()) } + /// Workaround to handle redirects, e.g. `touch f && tail -f - < f` fn handle_redirect(&self) -> PathBuf { if cfg!(unix) && self.is_stdin() { From c7fede8afcd6bcccf5d41398fcceed0e81aadf6b Mon Sep 17 00:00:00 2001 From: Joining7943 <111500881+Joining7943@users.noreply.github.com> Date: Sat, 10 Sep 2022 01:12:28 +0200 Subject: [PATCH 2/2] tail: Add debugging output when running into todo() and fix metadata --- src/uu/tail/src/tail.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index d4f9c8a4e7f..65055f6a421 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -451,12 +451,22 @@ fn uu_tail(mut settings: Settings) -> UResult<()> { } } else { // TODO: [2021-10; jhscheer] how to handle block device or socket? + + // we're running into this todo() on macos sometimes accidentally, so here's some debug output + // to help identify the problem + dbg!(settings.paths); + dbg!(&path); + dbg!(path.to_string_lossy().to_string()); + dbg!(path.is_file()); + dbg!(path.exists()); + dbg!(path.is_stdin()); + dbg!(path_is_tailable); + dbg!(settings.stdin_is_pipe_or_fifo); + dbg!(display_name); todo!(); } } - let metadata = path.metadata().ok(); - if display_name.is_stdin() && !path.is_file() { if settings.verbose { files.print_header(&display_name, !first_header); @@ -496,6 +506,7 @@ fn uu_tail(mut settings: Settings) -> UResult<()> { } else if path_is_tailable { match File::open(&path) { Ok(mut file) => { + let metadata = path.metadata().ok(); if settings.verbose { files.print_header(&display_name, !first_header); first_header = false; @@ -544,6 +555,9 @@ fn uu_tail(mut settings: Settings) -> UResult<()> { } else { path.to_owned() }; + + let metadata = path.metadata().ok(); // TODO isn't metadata always None here? + // Insert non-is_tailable() paths into `files.map` files.insert( &path,