From 5e77bab66325f9fb2a3b9d8875cadf036646b1b3 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Wed, 27 May 2026 13:49:20 +0900 Subject: [PATCH] buf_copy: remove thin wrapper & useless conversion --- src/uucore/src/lib/features/buf_copy.rs | 22 +++++++++---- src/uucore/src/lib/features/buf_copy/linux.rs | 33 ------------------- src/uucore/src/lib/features/buf_copy/other.rs | 27 --------------- 3 files changed, 16 insertions(+), 66 deletions(-) delete mode 100644 src/uucore/src/lib/features/buf_copy/linux.rs delete mode 100644 src/uucore/src/lib/features/buf_copy/other.rs diff --git a/src/uucore/src/lib/features/buf_copy.rs b/src/uucore/src/lib/features/buf_copy.rs index 1891a48785f..9943488c7ba 100644 --- a/src/uucore/src/lib/features/buf_copy.rs +++ b/src/uucore/src/lib/features/buf_copy.rs @@ -10,17 +10,27 @@ //! does not handle copying special files (e.g pipes, character/block devices). #[cfg(any(target_os = "linux", target_os = "android"))] -pub mod linux; +use std::os::fd::AsFd; #[cfg(any(target_os = "linux", target_os = "android"))] -pub use linux::*; +pub fn copy_stream( + src: &mut (impl std::io::Read + AsFd), + dest: &mut impl AsFd, +) -> std::io::Result<()> { + // try to splice() system call for throughput + if crate::pipes::splice_unbounded_auto(src, dest)?.is_err() { + // 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 slower than our splice + std::io::copy(src, &mut crate::io::RawWriter(dest))?; + } + Ok(()) +} #[cfg(not(any(target_os = "linux", target_os = "android")))] -pub mod other; -#[cfg(not(any(target_os = "linux", target_os = "android")))] -pub use other::copy_stream; +pub use std::io::copy as copy_stream; #[cfg(test)] -#[cfg(any(target_os = "linux", target_os = "android"))] // copy_stream is a thin wrapper for io::copy. nothing to test... +#[cfg(any(target_os = "linux", target_os = "android"))] // copy_stream is io::copy on other platforms. nothing to test. mod tests { use super::*; use std::fs::File; diff --git a/src/uucore/src/lib/features/buf_copy/linux.rs b/src/uucore/src/lib/features/buf_copy/linux.rs deleted file mode 100644 index 86cbf03696e..00000000000 --- a/src/uucore/src/lib/features/buf_copy/linux.rs +++ /dev/null @@ -1,33 +0,0 @@ -// This file is part of the uutils coreutils package. -// -// For the full copyright and license information, please view the LICENSE -// file that was distributed with this source code. - -//! Buffer-based copying implementation for Linux and Android. -use std::os::fd::AsFd; - -/// Copy data from `Read` implementor `source` into a `Write` implementor -/// `dest`. This works by reading a chunk of data from `source` and writing the -/// data to `dest` in a loop. -/// -/// This function uses the Linux-specific `splice` call when possible which does -/// not use any intermediate user-space buffer. It falls backs to -/// `std::io::copy` when the call fails and is still recoverable. -/// -/// # Arguments -/// * `source` - `Read` implementor to copy data from. -/// * `dest` - `Write` implementor to copy data to. -pub fn copy_stream( - src: &mut (impl std::io::Read + AsFd), - dest: &mut impl AsFd, -) -> 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)?.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 - std::io::copy(src, &mut crate::io::RawWriter(dest))?; - } - Ok(()) -} diff --git a/src/uucore/src/lib/features/buf_copy/other.rs b/src/uucore/src/lib/features/buf_copy/other.rs deleted file mode 100644 index 6b435b8d02d..00000000000 --- a/src/uucore/src/lib/features/buf_copy/other.rs +++ /dev/null @@ -1,27 +0,0 @@ -// This file is part of the uutils coreutils package. -// -// For the full copyright and license information, please view the LICENSE -// file that was distributed with this source code. -//! -//! Buffer-based copying implementation for other platforms. - -use std::io::{Read, Write}; - -use crate::error::UResult; - -/// Copy data from `Read` implementor `source` into a `Write` implementor -/// `dest`. This works by reading a chunk of data from `source` and writing the -/// data to `dest` in a loop, using std::io::copy. This is implemented for -/// non-Linux platforms. -/// -/// # Arguments -/// * `source` - `Read` implementor to copy data from. -/// * `dest` - `Write` implementor to copy data to. -pub fn copy_stream(src: &mut R, dest: &mut S) -> UResult<()> -where - R: Read, - S: Write, -{ - std::io::copy(src, dest)?; - Ok(()) -}