From ca3e965d688739916016d4fe1a277701b44f3445 Mon Sep 17 00:00:00 2001 From: Daniel Syauqi Date: Thu, 8 Oct 2026 14:33:08 +0800 Subject: [PATCH] touch: simplify Unix access error check --- src/uu/touch/src/touch.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index c51c6dfd8..aed09dff7 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -457,16 +457,13 @@ fn create_without_truncate(path: &Path) -> std::io::Result { // GNU reports ordinary access failures as "cannot touch", while -c and -h // report failures to update timestamps as "setting times of". +#[cfg(unix)] fn cannot_touch_on_access_error(opts: &Options, error: &Error) -> bool { - if opts.no_create || opts.no_deref || error.kind() != ErrorKind::PermissionDenied { - return false; - } - - #[cfg(unix)] - if error.raw_os_error() == Some(libc::EACCES) { - return true; - } + !opts.no_create && !opts.no_deref && error.raw_os_error() == Some(libc::EACCES) +} +#[cfg(not(unix))] +fn cannot_touch_on_access_error(_opts: &Options, _error: &Error) -> bool { false }