From 5dd9f377dbba5bf52bbdd1c58eac410dae60b98d Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sat, 23 May 2026 22:52:04 +0900 Subject: [PATCH] pipes.rs: replace bool by Result<(),()> --- src/uu/cat/src/cat.rs | 2 +- src/uu/tail/src/tail.rs | 2 +- src/uucore/src/lib/features/buf_copy/linux.rs | 2 +- src/uucore/src/lib/features/pipes.rs | 19 ++++++++++--------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index a2ddcc22f..226c43a7c 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -481,7 +481,7 @@ fn print_fast(handle: &mut InputHandle) -> CatResult<()> { let mut stdout = stdout; // Try to use the splice() system call for faster writing. If it works, we're done. #[cfg(any(target_os = "linux", target_os = "android"))] - if !uucore::pipes::splice_unbounded_auto(&handle.reader, &mut stdout)? + if uucore::pipes::splice_unbounded_auto(&handle.reader, &mut stdout)?.is_ok() && !uucore::pipes::might_fuse(&handle.reader) { return Ok(()); diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index a9307d4cd..7ba1335ad 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -596,7 +596,7 @@ fn print_target_section< } } else { #[cfg(any(target_os = "linux", target_os = "android"))] - if uucore::pipes::splice_unbounded_auto(file, &mut stdout)? { + if uucore::pipes::splice_unbounded_auto(file, &mut stdout)?.is_err() { io::copy(file, &mut stdout)?; } #[cfg(not(any(target_os = "linux", target_os = "android")))] diff --git a/src/uucore/src/lib/features/buf_copy/linux.rs b/src/uucore/src/lib/features/buf_copy/linux.rs index 7de3ba609..86cbf0369 100644 --- a/src/uucore/src/lib/features/buf_copy/linux.rs +++ b/src/uucore/src/lib/features/buf_copy/linux.rs @@ -23,7 +23,7 @@ pub fn copy_stream( ) -> crate::error::UResult<()> { // If we're on Linux or Android, try to use the splice() system call // for faster writing. If it works, we're done. - if crate::pipes::splice_unbounded_auto(src, dest)? { + if crate::pipes::splice_unbounded_auto(src, dest)?.is_err() { // If the splice() call failed, fall back on writing "without buffering", or order of output would be wrong // unrelated for cp /dev/stdin since cp does not have multiple input? // RawWriter also removes io::copy's specialization diff --git a/src/uucore/src/lib/features/pipes.rs b/src/uucore/src/lib/features/pipes.rs index fc39829a2..44e7a74cc 100644 --- a/src/uucore/src/lib/features/pipes.rs +++ b/src/uucore/src/lib/features/pipes.rs @@ -142,16 +142,17 @@ pub fn splice_unbounded_broker( /// try splice_unbounded 1st and splice_unbounded_broker if both of in/output are not pipe /// -/// return true if write fallback is needed -/// (the fallback will be embedded to this function in the future) +/// see splice_unbounded_broker to handle returned error #[inline] -pub fn splice_unbounded_auto(source: &impl AsFd, dest: &mut impl AsFd) -> std::io::Result { - // use splice to check that input or output is pipe which is efficient - let fallback = match splice(&source, dest, MAX_ROOTLESS_PIPE_SIZE) { - Ok(_) => splice_unbounded(source, dest).is_err(), - _ => splice_unbounded_broker(source, dest)?.is_err(), - }; - Ok(fallback) +pub fn splice_unbounded_auto( + source: &impl AsFd, + dest: &mut impl AsFd, +) -> std::io::Result> { + if splice_unbounded(source, dest).is_err() { + // input or output is not pipe + return splice_unbounded_broker(source, dest); + } + Ok(Ok(())) } /// splice `n` bytes with read/write fallback