From 49cf918bb939cc9d735c80af8e0897f91d30294c Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 30 Jun 2026 12:33:13 +0900 Subject: [PATCH] sum: remove .is_dir() overhead --- src/uu/sum/src/sum.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index b2d276982c2..3dadd3594c5 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -78,14 +78,15 @@ fn open(name: &OsString) -> UResult { // Silent the warning as we want to the error message match path.metadata() { - Ok(_) => { - if path.is_dir() { - return Err(USimpleError::new( - 1, - translate!("sum-error-is-directory", "name" => name.maybe_quote()), - )); - } + // some platforms cannot catch this as read error. Needs additional cost by stat + #[cfg(any(target_os = "wasi", target_os = "windows"))] + Ok(_) if path.is_dir() => { + return Err(USimpleError::new( + 1, + translate!("sum-error-is-directory", "name" => name.maybe_quote()), + )); } + Ok(_) => {} Err(err) => { if err.kind() == ErrorKind::NotFound { return Err(USimpleError::new(