From ceb2e993c024b58b9b7cce0f45e1863b306f73e7 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Fri, 22 Apr 2022 12:09:39 +0200 Subject: [PATCH] tail: update readmes --- README.md | 9 +++++---- src/uu/tail/README.md | 8 +++----- src/uu/tail/src/tail.rs | 20 +++++++++++++++----- tests/by-util/test_tail.rs | 26 +++++++------------------- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 2dfffa017..0b1c7b104 100644 --- a/README.md +++ b/README.md @@ -422,10 +422,10 @@ See https://github.com/uutils/coreutils/issues/3336 for the main meta bugs | comm | sort | | | csplit | split | | | cut | tac | | -| dircolors | tail | | -| dirname | test | | -| du | dir | | -| echo | vdir | | +| dircolors | test | | +| dirname | dir | | +| du | vdir | | +| echo | | | | env | | | | expand | | | | factor | | | @@ -478,6 +478,7 @@ See https://github.com/uutils/coreutils/issues/3336 for the main meta bugs | stdbuf | | | | sum | | | | sync | | | +| tail | | | | tee | | | | timeout | | | | touch | | | diff --git a/src/uu/tail/README.md b/src/uu/tail/README.md index ef412a5d6..11d78b49e 100644 --- a/src/uu/tail/README.md +++ b/src/uu/tail/README.md @@ -1,7 +1,5 @@ # Notes / ToDO -- Rudimentary tail implementation. - ## Missing features ### Flags with features @@ -11,13 +9,13 @@ - [ ] `--max-unchanged-stats` (only meaningful with `--follow=name` `---disable-inotify`) - [x] `---disable-inotify` (three hyphens is correct) - [x] `--follow=name' -- [ ] `--retry' -- [ ] `-F' (same as `--follow=name` `--retry`) +- [x] `--retry' +- [x] `-F' (same as `--follow=name` `--retry`) ### Others - [ ] The current implementation doesn't follow stdin in non-unix platforms -- [ ] Since the current implementation uses a crate for polling, the following is difficult to implement: +- [ ] Since the current implementation uses a crate for polling, these flags are too complex to implement: - [ ] `--max-unchanged-stats` - [ ] check whether process p is alive at least every number of seconds (relevant for `--pid`) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index da78e6a89..d6399a51a 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -33,11 +33,9 @@ use std::collections::HashMap; use std::collections::VecDeque; use std::ffi::OsString; use std::fmt; -use std::fs::metadata; use std::fs::{File, Metadata}; use std::io::{stdin, stdout, BufRead, BufReader, Read, Seek, SeekFrom, Write}; use std::io::{Error, ErrorKind}; -use std::os::unix::prelude::FileTypeExt; use std::path::{Path, PathBuf}; use std::sync::mpsc::{self, channel}; use std::time::Duration; @@ -52,6 +50,10 @@ use uucore::ringbuffer::RingBuffer; use crate::platform::stdin_is_pipe_or_fifo; #[cfg(unix)] use std::os::unix::fs::MetadataExt; +#[cfg(unix)] +use std::os::unix::prelude::FileTypeExt; +#[cfg(unix)] +use std::fs::metadata; const ABOUT: &str = "\ Print the last 10 lines of each FILE to standard output.\n\ @@ -85,7 +87,7 @@ pub mod options { pub static PID: &str = "pid"; pub static SLEEP_INT: &str = "sleep-interval"; pub static ZERO_TERM: &str = "zero-terminated"; - pub static DISABLE_INOTIFY_TERM: &str = "disable-inotify"; + pub static DISABLE_INOTIFY_TERM: &str = "-disable-inotify"; pub static USE_POLLING: &str = "use-polling"; pub static RETRY: &str = "retry"; pub static FOLLOW_RETRY: &str = "F"; @@ -1302,8 +1304,16 @@ impl PathExt for Path { !matches!(self.parent(), Some(parent) if parent.is_dir()) } fn is_tailable(&self) -> bool { - // TODO: [2021-10; jhscheer] what about fifos? - self.is_file() || (self.exists() && metadata(self).unwrap().file_type().is_char_device()) + #[cfg(unix)] + { + // TODO: [2021-10; jhscheer] what about fifos? + self.is_file() + || (self.exists() && metadata(self).unwrap().file_type().is_char_device()) + } + #[cfg(not(unix))] + { + self.is_file() + } } } diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 8da3ebc8f..ded1d4ac1 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -940,7 +940,7 @@ fn test_retry7() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android fn test_retry8() { // Ensure that inotify will switch to polling mode if directory // of the watched file was initially missing and later created. @@ -994,7 +994,7 @@ fn test_retry8() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android fn test_retry9() { // gnu/tests/tail-2/inotify-dir-recreate.sh // Ensure that inotify will switch to polling mode if directory @@ -1069,7 +1069,7 @@ fn test_retry9() { } #[test] -#[cfg(unix)] +#[cfg(target_os = "linux")] // FIXME: fix this test for BSD/macOS fn test_follow_descriptor_vs_rename1() { // gnu/tests/tail-2/descriptor-vs-rename.sh // $ ((rm -f A && touch A && sleep 1 && echo -n "A\n" >> A && sleep 1 && \ @@ -1092,14 +1092,8 @@ fn test_follow_descriptor_vs_rename1() { "--disable-inotify", ]; - #[cfg(target_os = "linux")] - let i = 2; - // FIXME: fix the case without `--disable-inotify` for BSD/macOS - #[cfg(not(target_os = "linux"))] - let i = 1; - let delay = 500; - for _ in 0..i { + for _ in 0..2 { at.touch(file_a); let mut p = ts.ucmd().args(&args).run_no_wait(); @@ -1152,14 +1146,8 @@ fn test_follow_descriptor_vs_rename2() { "--disable-inotify", ]; - #[cfg(target_os = "linux")] - let i = 2; - // TODO: fix the case without `--disable-inotify` for bsd/macos - #[cfg(not(target_os = "linux"))] - let i = 1; - let delay = 100; - for _ in 0..i { + for _ in 0..2 { at.touch(file_a); at.touch(file_b); let mut p = ts.ucmd().args(&args).run_no_wait(); @@ -1324,7 +1312,7 @@ fn test_follow_name_truncate3() { } #[test] -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android fn test_follow_name_move_create() { // This test triggers a move/create event while `tail --follow=name logfile` is running. // ((sleep 2 && mv logfile backup && sleep 2 && cp backup logfile &)>/dev/null 2>&1 &) ; tail --follow=name logfile @@ -1414,7 +1402,7 @@ fn test_follow_name_move() { fn test_follow_inotify_only_regular() { // The GNU test inotify-only-regular.sh uses strace to ensure that `tail -f` // doesn't make inotify syscalls and only uses inotify for regular files or fifos. - // We just check if tailing a character device has the same behaviour than GNU's tail. + // We just check if tailing a character device has the same behavior as GNU's tail. let ts = TestScenario::new(util_name!());