pipes.rs: replace bool by Result<(),()>

This commit is contained in:
oech3
2026-05-23 22:52:04 +09:00
committed by Daniel Hofstetter
parent 9d3bafc23e
commit 5dd9f377db
4 changed files with 13 additions and 12 deletions
+1 -1
View File
@@ -481,7 +481,7 @@ fn print_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> 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(());
+1 -1
View File
@@ -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")))]
@@ -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? <https://github.com/uutils/coreutils/issues/5186>
// RawWriter also removes io::copy's specialization
+10 -9
View File
@@ -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<bool> {
// 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<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