diff options
| author | Nicolas Koch <nioko1337@gmail.com> | 2018-05-29 23:42:42 +0200 |
|---|---|---|
| committer | Nicolas Koch <nioko1337@gmail.com> | 2018-05-29 23:42:42 +0200 |
| commit | c7d6a0130b6b76b65982916198e7de2b348f9718 (patch) | |
| tree | 807d3b51d50bd8f99e65bc768bb416a5ec16fd92 /src/libstd/sys | |
| parent | 3b271eb039d22a4b31caed29a2aac0a9ac604902 (diff) | |
| download | rust-c7d6a0130b6b76b65982916198e7de2b348f9718.tar.gz rust-c7d6a0130b6b76b65982916198e7de2b348f9718.zip | |
Fix additional nits:
- compute bytes_to_copy more elegantly - add assert that written is 0 in fallback case
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 56075c5e8d0..38f1ac472fa 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -780,6 +780,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { #[cfg(any(target_os = "linux", target_os = "android"))] pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { + use cmp; use fs::{File, set_permissions}; use sync::atomic::{AtomicBool, Ordering}; @@ -822,13 +823,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { let mut written = 0u64; while written < len { let copy_result = if has_copy_file_range { - // FIXME: should ideally use TryFrom - let bytes_to_copy = if len - written > usize::max_value() as u64 { - usize::max_value() - } else { - (len - written) as usize - }; - + let bytes_to_copy = cmp::min(len - written, usize::max_value() as u64) as usize; let copy_result = unsafe { // We actually don't have to adjust the offsets, // because copy_file_range adjusts the file offset automatically @@ -856,6 +851,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { Some(os_err) if os_err == libc::ENOSYS || os_err == libc::EXDEV => { // Either kernel is too old or the files are not mounted on the same fs. // Try again with fallback method + assert_eq!(written, 0); let ret = io::copy(&mut reader, &mut writer)?; set_permissions(to, perm)?; return Ok(ret) |
