From d79451af97d394c5d86e7f74812841f53fcfb2a4 Mon Sep 17 00:00:00 2001 From: Devel Date: Wed, 12 Aug 2026 11:32:02 +0300 Subject: [PATCH] use imports instead of absoulte path when using strip_errno seperate import for sync group strip_errno in false.rs Co-authored-by: oech3 <79379754+oech3@users.noreply.github.com> remove redudant import and move import to conditional compilation in sync Apply suggestions from code review Co-authored-by: oech3 <79379754+oech3@users.noreply.github.com> cargo fmt group strip_errno in uucore import group import in unix.rs group imports --- src/uu/false/src/false.rs | 3 ++- src/uu/head/src/head.rs | 4 ++-- src/uu/mkdir/src/mkdir.rs | 4 ++-- src/uu/split/src/platform/unix.rs | 4 ++-- src/uu/split/src/platform/windows.rs | 3 ++- src/uu/sync/src/sync.rs | 3 ++- src/uu/true/src/true.rs | 4 ++-- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 519df6df4bb..f7c3a97a79a 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -4,6 +4,7 @@ // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; use std::io::{self, Write as _}; +use uucore::error::strip_errno; use uucore::{crate_version, translate}; // uucore::main does not support no-result @@ -25,7 +26,7 @@ pub fn uumain(mut args: impl uucore::Args) -> i32 { if let Err(e) = res && e.kind() != io::ErrorKind::BrokenPipe { - let _ = writeln!(io::stderr(), "false: {}", uucore::error::strip_errno(&e)); + let _ = writeln!(io::stderr(), "false: {}", strip_errno(&e)); } 1 } diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index 61082204734..9a1919679e0 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -18,7 +18,7 @@ use std::path::Path; use std::path::PathBuf; use thiserror::Error; use uucore::display::{Quotable, print_verbatim}; -use uucore::error::{FromIo, UError, UResult, USimpleError}; +use uucore::error::{FromIo, UError, UResult, USimpleError, strip_errno}; use uucore::line_ending::LineEnding; use uucore::show; use uucore::translate; @@ -165,7 +165,7 @@ impl HeadOptions { fn wrap_in_stdout_error(err: io::Error) -> io::Error { io::Error::new( err.kind(), - translate!("head-error-writing-stdout", "err" => uucore::error::strip_errno(&err)), + translate!("head-error-writing-stdout", "err" => strip_errno(&err)), ) } diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 7d009f4f32d..d41fcb9d52d 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -13,7 +13,7 @@ use std::io::{Write, stdout}; use std::path::{Path, PathBuf}; #[cfg(not(windows))] use uucore::error::ExitCode; -use uucore::error::{UResult, USimpleError}; +use uucore::error::{UResult, USimpleError, strip_errno}; #[cfg(not(windows))] use uucore::mode; use uucore::translate; @@ -374,7 +374,7 @@ fn create_single_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<( } Err(e) => Err(USimpleError::new( 1, - translate!("mkdir-error-cannot-create-directory", "path" => path.display(), "error" => uucore::error::strip_errno(&e)), + translate!("mkdir-error-cannot-create-directory", "path" => path.display(), "error" => strip_errno(&e)), )), } } diff --git a/src/uu/split/src/platform/unix.rs b/src/uu/split/src/platform/unix.rs index dd9798539a9..caeaede59b3 100644 --- a/src/uu/split/src/platform/unix.rs +++ b/src/uu/split/src/platform/unix.rs @@ -11,7 +11,7 @@ use std::io::{ErrorKind, Write}; use std::path::Path; use std::process::{Child, Command, Stdio}; use uucore::display::Quotable; -use uucore::error::USimpleError; +use uucore::error::{USimpleError, strip_errno}; use uucore::fs; use uucore::fs::FileInformation; use uucore::show; @@ -197,7 +197,7 @@ fn create_or_truncate_output_file(input: &OsStr, filename: &OsStr) -> Result Error { - let e = uucore::error::strip_errno(&e); + let e = strip_errno(&e); Error::other(format!("{}: {e}", filename.quote())) } diff --git a/src/uu/split/src/platform/windows.rs b/src/uu/split/src/platform/windows.rs index ef70f709c3f..70bcfa1e273 100644 --- a/src/uu/split/src/platform/windows.rs +++ b/src/uu/split/src/platform/windows.rs @@ -7,6 +7,7 @@ use std::ffi::OsStr; use std::io::{Error, ErrorKind, Result}; use std::path::Path; use uucore::display::Quotable; +use uucore::error::strip_errno; use uucore::fs; use uucore::translate; @@ -71,7 +72,7 @@ fn create_or_truncate_output_file(input: &OsStr, filename: &OsStr) -> Result Error { - let e = uucore::error::strip_errno(&e); + let e = strip_errno(&e); Error::other(format!("{}: {e}", filename.quote())) } diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index ff43395953f..c3d1994212b 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -218,6 +218,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // open with O_NONBLOCK to handle fifo files #[cfg(any(target_os = "linux", target_os = "android"))] { + use uucore::error::strip_errno; let path = Path::new(f); if let Err(e) = rustix::fs::open( path, @@ -225,7 +226,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { rustix::fs::Mode::empty(), ) && (e != rustix::io::Errno::ACCESS || path.is_dir()) { - let msg = translate!("sync-error-opening-file", "file" => f.quote(), "err" => uucore::error::strip_errno(&std::io::Error::from(e))); + let msg = translate!("sync-error-opening-file", "file" => f.quote(), "err" => strip_errno(&std::io::Error::from(e))); show_error!("{msg}"); set_exit_code(1); } diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index fbfbbe74e72..a4d4714cb98 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; use std::io::{self, Write as _}; -use uucore::{crate_version, translate}; +use uucore::{crate_version, error::strip_errno, translate}; // uucore::main does not support no-result pub fn uumain(mut args: impl uucore::Args) -> i32 { @@ -26,7 +26,7 @@ pub fn uumain(mut args: impl uucore::Args) -> i32 { && e.kind() != io::ErrorKind::BrokenPipe { // Try to display this error. - let _ = writeln!(io::stderr(), "true: {}", uucore::error::strip_errno(&e)); + let _ = writeln!(io::stderr(), "true: {}", strip_errno(&e)); // Mirror GNU options. When failing to print warnings or version flags, then we exit // with FAIL. This avoids allocation some error information which may result in yet // other types of failure.