diff --git a/src/uu/cp/src/platform/linux.rs b/src/uu/cp/src/platform/linux.rs index 427593ae25d..de02e201e65 100644 --- a/src/uu/cp/src/platform/linux.rs +++ b/src/uu/cp/src/platform/linux.rs @@ -214,7 +214,7 @@ fn check_dest_is_fifo(dest: &Path) -> bool { } /// Copy the contents of a stream from `source` to `dest`. -fn copy_stream

(source: P, dest: P) -> std::io::Result +fn copy_stream

(source: P, dest: P) -> std::io::Result<()> where P: AsRef, { @@ -250,10 +250,10 @@ where dst_file.set_len(0)?; } - let num_bytes_copied = buf_copy::copy_stream(&mut src_file, &mut dst_file) + buf_copy::copy_stream(&mut src_file, &mut dst_file) .map_err(|e| std::io::Error::other(format!("{e}")))?; - Ok(num_bytes_copied) + Ok(()) } /// Copies `source` to `dest` using copy-on-write if possible. diff --git a/src/uucore/src/lib/features/buf_copy.rs b/src/uucore/src/lib/features/buf_copy.rs index 3ab2814bc24..bff94e94e38 100644 --- a/src/uucore/src/lib/features/buf_copy.rs +++ b/src/uucore/src/lib/features/buf_copy.rs @@ -75,9 +75,8 @@ mod tests { let thread = thread::spawn(move || { pipe_write.write_all(data).unwrap(); }); - let result = copy_stream(&mut pipe_read, &mut dest_file).unwrap(); + copy_stream(&mut pipe_read, &mut dest_file).unwrap(); thread.join().unwrap(); - assert_eq!(result, data.len() as u64); // We would have been at the end already, so seek again to the start. dest_file.seek(SeekFrom::Start(0)).unwrap(); @@ -104,13 +103,12 @@ mod tests { src_file.sync_all().unwrap(); let mut src_file = File::open(&src_path).unwrap(); - let bytes_copied = copy_stream(&mut src_file, &mut dest_file).unwrap(); + copy_stream(&mut src_file, &mut dest_file).unwrap(); let mut dest_file = File::open(&dest_path).unwrap(); let mut buf = Vec::new(); dest_file.read_to_end(&mut buf).unwrap(); - assert_eq!(bytes_copied as usize, data.len()); assert_eq!(buf, data); } } diff --git a/src/uucore/src/lib/features/buf_copy/linux.rs b/src/uucore/src/lib/features/buf_copy/linux.rs index 3f7768794c0..592553b0956 100644 --- a/src/uucore/src/lib/features/buf_copy/linux.rs +++ b/src/uucore/src/lib/features/buf_copy/linux.rs @@ -48,12 +48,7 @@ impl From for Error { /// # Arguments /// * `source` - `Read` implementor to copy data from. /// * `dest` - `Write` implementor to copy data to. -/// -/// # Returns -/// -/// Result of operation and bytes successfully written (as a `u64`) when -/// operation is successful. -pub fn copy_stream(src: &mut R, dest: &mut S) -> UResult +pub fn copy_stream(src: &mut R, dest: &mut S) -> UResult<()> where R: Read + AsFd + AsRawFd, S: Write + AsFd + AsRawFd, @@ -62,11 +57,11 @@ where // for faster writing. If it works, we're done. let result = splice_write(src, &dest.as_fd())?; if !result.1 { - return Ok(result.0); + return Ok(()); } // If the splice() call failed, fall back on slower writing. - let result = std::io::copy(src, dest)?; + std::io::copy(src, dest)?; // If the splice() call failed and there has been some data written to // stdout via while loop above AND there will be second splice() call @@ -74,7 +69,7 @@ where // the data buffered in stdout.lock. Therefore additional explicit flush // is required here. dest.flush()?; - Ok(result) + Ok(()) } /// Write from source `handle` into destination `write_fd` using Linux-specific diff --git a/src/uucore/src/lib/features/buf_copy/other.rs b/src/uucore/src/lib/features/buf_copy/other.rs index 61dd13e6cea..6b435b8d02d 100644 --- a/src/uucore/src/lib/features/buf_copy/other.rs +++ b/src/uucore/src/lib/features/buf_copy/other.rs @@ -17,16 +17,11 @@ use crate::error::UResult; /// # Arguments /// * `source` - `Read` implementor to copy data from. /// * `dest` - `Write` implementor to copy data to. -/// -/// # Returns -/// -/// Result of operation and bytes successfully written (as a `u64`) when -/// operation is successful. -pub fn copy_stream(src: &mut R, dest: &mut S) -> UResult +pub fn copy_stream(src: &mut R, dest: &mut S) -> UResult<()> where R: Read, S: Write, { - let result = std::io::copy(src, dest)?; - Ok(result) + std::io::copy(src, dest)?; + Ok(()) }