Skip to content

Commit

Permalink
Use pwritev rather than copy_file_range, as it may be too recent
Browse files Browse the repository at this point in the history
Also, tentatively fix "mismatched types" error for non-64b arch
  • Loading branch information
pimzero committed Aug 2, 2022
1 parent 34b6cbc commit 53ae311
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// For the full copyright and license information, please view the LICENSE file
// that was distributed with this source code.

// spell-checker:ignore (ToDO) ficlone ftruncate linkgs lstat nlink nlinks pathbuf reflink strs xattrs symlinked
// spell-checker:ignore (ToDO) ficlone ftruncate linkgs lstat nlink nlinks pathbuf pwrite reflink strs xattrs symlinked

#[macro_use]
extern crate quick_error;
Expand Down Expand Up @@ -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,
Expand All @@ -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(())
},
Expand Down

0 comments on commit 53ae311

Please sign in to comment.