From 5be06c8d7ee57a804b0801fcd735f5a7bc76ede8 Mon Sep 17 00:00:00 2001 From: Pierre Marsais Date: Tue, 2 Aug 2022 20:37:09 +0100 Subject: [PATCH] Use pwritev rather than copy_file_range, as it may be too recent Also, tentatively fix "mismatched types" error for non-64b arch --- src/uu/cp/src/cp.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index eaf5ef121d2..572e4062c75 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1617,7 +1617,7 @@ fn copy_on_write_linux( } (_, SparseMode::Always) => unsafe { let size: usize = src_file.metadata()?.size().try_into().unwrap(); - if libc::ftruncate(dst_file.as_raw_fd(), i64::try_from(size).unwrap()) < 0 { + if libc::ftruncate(dst_file.as_raw_fd(), size.try_into().unwrap()) < 0 { return Err(format!( "failed to ftruncate {:?} to size {}: {}", dest, @@ -1633,25 +1633,18 @@ fn copy_on_write_linux( while current_offset < size { use std::io::Read; - let (mut off_src, mut off_dst): (i64, i64) = ( - current_offset.try_into().unwrap(), - current_offset.try_into().unwrap(), - ); let this_read = src_file.read(&mut buf)?; - current_offset += this_read; if buf.iter().any(|&x| x != 0) { - const COPY_FLAGS: u32 = 0; - libc::copy_file_range( - src_file.as_raw_fd(), - &mut off_src, + libc::pwrite( dst_file.as_raw_fd(), - &mut off_dst, + buf.as_ptr() as *const libc::c_void, this_read, - COPY_FLAGS, + current_offset.try_into().unwrap(), ); } + current_offset += this_read; } Ok(()) },