Skip to content

Commit c296b6b

Browse files
committed
Rollup merge of rust-lang#51213 - nicokoch:copy_permissions, r=cramertj
fs: copy: Use File::set_permissions instead of fs::set_permissions We already got the open file descriptor at this point. Don't make the kernel resolve the path again.
2 parents 7bf60b7 + c5ee3b6 commit c296b6b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: src/libstd/sys/unix/fs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
817817

818818
#[cfg(not(any(target_os = "linux", target_os = "android")))]
819819
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
820-
use fs::{File, set_permissions};
820+
use fs::File;
821821
if !from.is_file() {
822822
return Err(Error::new(ErrorKind::InvalidInput,
823823
"the source path is not an existing regular file"))
@@ -828,14 +828,14 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
828828
let perm = reader.metadata()?.permissions();
829829

830830
let ret = io::copy(&mut reader, &mut writer)?;
831-
set_permissions(to, perm)?;
831+
writer.set_permissions(perm)?;
832832
Ok(ret)
833833
}
834834

835835
#[cfg(any(target_os = "linux", target_os = "android"))]
836836
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
837837
use cmp;
838-
use fs::{File, set_permissions};
838+
use fs::File;
839839
use sync::atomic::{AtomicBool, Ordering};
840840

841841
// Kernel prior to 4.5 don't have copy_file_range
@@ -907,14 +907,14 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
907907
// Try again with fallback method
908908
assert_eq!(written, 0);
909909
let ret = io::copy(&mut reader, &mut writer)?;
910-
set_permissions(to, perm)?;
910+
writer.set_permissions(perm)?;
911911
return Ok(ret)
912912
},
913913
_ => return Err(err),
914914
}
915915
}
916916
}
917917
}
918-
set_permissions(to, perm)?;
918+
writer.set_permissions(perm)?;
919919
Ok(written)
920920
}

0 commit comments

Comments
 (0)