Skip to content

Commit 9be5e76

Browse files
Alex Saveaugitbot
Alex Saveau
authored and
gitbot
committed
Unify fs::copy and io::copy
1 parent 5bafafb commit 9be5e76

File tree

1 file changed

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

1 file changed

+1
-19
lines changed

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

+1-19
Original file line numberDiff line numberDiff line change
@@ -1984,32 +1984,14 @@ fn open_to_and_set_permissions(
19841984
Ok((writer, writer_metadata))
19851985
}
19861986

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

19921992
io::copy(&mut reader, &mut writer)
19931993
}
19941994

1995-
#[cfg(any(target_os = "linux", target_os = "android"))]
1996-
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1997-
let (mut reader, reader_metadata) = open_from(from)?;
1998-
let max_len = u64::MAX;
1999-
let (mut writer, _) = open_to_and_set_permissions(to, reader_metadata)?;
2000-
2001-
use super::kernel_copy::{CopyResult, copy_regular_files};
2002-
2003-
match copy_regular_files(reader.as_raw_fd(), writer.as_raw_fd(), max_len) {
2004-
CopyResult::Ended(bytes) => Ok(bytes),
2005-
CopyResult::Error(e, _) => Err(e),
2006-
CopyResult::Fallback(written) => match io::copy::generic_copy(&mut reader, &mut writer) {
2007-
Ok(bytes) => Ok(bytes + written),
2008-
Err(e) => Err(e),
2009-
},
2010-
}
2011-
}
2012-
20131995
#[cfg(target_vendor = "apple")]
20141996
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
20151997
const COPYFILE_ALL: libc::copyfile_flags_t = libc::COPYFILE_METADATA | libc::COPYFILE_DATA;

0 commit comments

Comments
 (0)