Skip to content

Commit 2b4334e

Browse files
author
Alex Saveau
committed
Unify fs::copy and io::copy
1 parent 588a420 commit 2b4334e

File tree

1 file changed

+1
-19
lines changed
  • library/std/src/sys/pal/unix

1 file changed

+1
-19
lines changed

library/std/src/sys/pal/unix/fs.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1863,32 +1863,14 @@ fn open_to_and_set_permissions(
18631863
Ok((writer, writer_metadata))
18641864
}
18651865

1866-
#[cfg(not(any(target_os = "linux", target_os = "android", target_vendor = "apple")))]
1866+
#[cfg(not(target_vendor = "apple"))]
18671867
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
18681868
let (mut reader, reader_metadata) = open_from(from)?;
18691869
let (mut writer, _) = open_to_and_set_permissions(to, reader_metadata)?;
18701870

18711871
io::copy(&mut reader, &mut writer)
18721872
}
18731873

1874-
#[cfg(any(target_os = "linux", target_os = "android"))]
1875-
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1876-
let (mut reader, reader_metadata) = open_from(from)?;
1877-
let max_len = u64::MAX;
1878-
let (mut writer, _) = open_to_and_set_permissions(to, reader_metadata)?;
1879-
1880-
use super::kernel_copy::{CopyResult, copy_regular_files};
1881-
1882-
match copy_regular_files(reader.as_raw_fd(), writer.as_raw_fd(), max_len) {
1883-
CopyResult::Ended(bytes) => Ok(bytes),
1884-
CopyResult::Error(e, _) => Err(e),
1885-
CopyResult::Fallback(written) => match io::copy::generic_copy(&mut reader, &mut writer) {
1886-
Ok(bytes) => Ok(bytes + written),
1887-
Err(e) => Err(e),
1888-
},
1889-
}
1890-
}
1891-
18921874
#[cfg(target_vendor = "apple")]
18931875
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
18941876
const COPYFILE_ALL: libc::copyfile_flags_t = libc::COPYFILE_METADATA | libc::COPYFILE_DATA;

0 commit comments

Comments
 (0)