mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cp, uucore: remove unused returned u64
This commit is contained in:
@@ -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<P>(source: P, dest: P) -> std::io::Result<u64>
|
||||
fn copy_stream<P>(source: P, dest: P) -> std::io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +48,7 @@ impl From<rustix::io::Errno> 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<R, S>(src: &mut R, dest: &mut S) -> UResult<u64>
|
||||
pub fn copy_stream<R, S>(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
|
||||
|
||||
@@ -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<R, S>(src: &mut R, dest: &mut S) -> UResult<u64>
|
||||
pub fn copy_stream<R, S>(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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user