From 7e7f82cf5a8c00f41126670ca2c210641ecc64d9 Mon Sep 17 00:00:00 2001 From: Joining7943 <111500881+Joining7943@users.noreply.github.com> Date: Wed, 14 Sep 2022 15:51:23 +0200 Subject: [PATCH] tail: Cleanup imports cherry pick --- src/uu/tail/src/chunks.rs | 2 ++ src/uu/tail/src/follow/files.rs | 1 - src/uu/tail/src/follow/watch.rs | 4 ++-- src/uu/tail/src/paths.rs | 16 ++++------------ src/uu/tail/src/tail.rs | 14 ++++++-------- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/uu/tail/src/chunks.rs b/src/uu/tail/src/chunks.rs index acfc69a305b..7ad2e153b2a 100644 --- a/src/uu/tail/src/chunks.rs +++ b/src/uu/tail/src/chunks.rs @@ -7,7 +7,9 @@ //! or at the end of piped stdin with [`LinesChunk`] or [`BytesChunk`]. //! //! Use [`ReverseChunks::new`] to create a new iterator over chunks of bytes from the file. + // spell-checker:ignore (ToDO) filehandle BUFSIZ + use std::collections::VecDeque; use std::fs::File; use std::io::{BufRead, Read, Seek, SeekFrom, Write}; diff --git a/src/uu/tail/src/follow/files.rs b/src/uu/tail/src/follow/files.rs index 1be090217c0..c8cf8ff0699 100644 --- a/src/uu/tail/src/follow/files.rs +++ b/src/uu/tail/src/follow/files.rs @@ -13,7 +13,6 @@ use std::collections::hash_map::Keys; use std::collections::HashMap; use std::fs::{File, Metadata}; use std::io::{stdout, BufRead, BufReader, BufWriter}; - use std::path::{Path, PathBuf}; use uucore::error::UResult; diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index b00d85f44dd..c61ca63bc8e 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -13,8 +13,7 @@ use notify::{RecommendedWatcher, RecursiveMode, Watcher, WatcherKind}; use std::collections::VecDeque; use std::io::BufRead; use std::path::{Path, PathBuf}; -use std::sync::mpsc; -use std::sync::mpsc::{channel, Receiver}; +use std::sync::mpsc::{self, channel, Receiver}; use uucore::display::Quotable; use uucore::error::{set_exit_code, UResult, USimpleError}; @@ -91,6 +90,7 @@ pub struct WatcherService { /// platform specific event driven method. Since `use_polling` is subject to /// change during runtime it is moved out of [`Settings`]. pub use_polling: bool, + pub watcher_rx: Option, pub orphans: Vec, pub files: FileHandling, diff --git a/src/uu/tail/src/paths.rs b/src/uu/tail/src/paths.rs index 0ebb265b2a6..2136aae880e 100644 --- a/src/uu/tail/src/paths.rs +++ b/src/uu/tail/src/paths.rs @@ -5,24 +5,16 @@ // spell-checker:ignore tailable seekable stdlib (stdlib) -#[cfg(unix)] -use std::os::unix::fs::{FileTypeExt, MetadataExt}; - +use crate::args::Settings; +use crate::text; use std::collections::VecDeque; use std::fs::{File, Metadata}; use std::io::{Seek, SeekFrom}; +#[cfg(unix)] +use std::os::unix::fs::{FileTypeExt, MetadataExt}; use std::path::{Path, PathBuf}; - use uucore::error::UResult; -use crate::args::Settings; -use crate::text; - -// * This file is part of the uutils coreutils package. -// * -// * For the full copyright and license information, please view the LICENSE -// * file that was distributed with this source code. - #[derive(Debug, Clone)] pub enum InputKind { File(PathBuf), diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 2a76522d3e2..dbada9a3723 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -31,21 +31,19 @@ mod paths; mod platform; pub mod text; +pub use args::uu_app; +use args::{parse_args, FilterMode, Settings, Signum}; +use chunks::ReverseChunks; +use follow::WatcherService; +use paths::{FileExtTail, Input, InputKind, InputService, MetadataExtTail}; use same_file::Handle; use std::cmp::Ordering; use std::fs::File; use std::io::{self, stdin, stdout, BufRead, BufReader, BufWriter, Read, Seek, SeekFrom, Write}; use std::path::{Path, PathBuf}; - use uucore::display::Quotable; use uucore::error::{get_exit_code, set_exit_code, FromIo, UError, UResult, USimpleError}; -pub use args::uu_app; -use args::{parse_args, FilterMode, Settings, Signum}; -use chunks::ReverseChunks; -use follow::WatcherService; -use paths::{FileExtTail, Input, InputKind, InputService, MetadataExtTail}; - #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let settings = parse_args(args)?; @@ -96,7 +94,6 @@ fn uu_tail(settings: &Settings) -> UResult<()> { the input file is not a FIFO, pipe, or regular file, it is unspecified whether or not the -f option shall be ignored. */ - if !input_service.has_only_stdin() { follow::follow(watcher_service, settings)?; } @@ -196,6 +193,7 @@ fn tail_file( } fn tail_stdin( + // TODO: remove settings settings: &Settings, input_service: &mut InputService, input: &Input,