Skip to content

Commit

Permalink
Rollup merge of rust-lang#51213 - nicokoch:copy_permissions, r=cramertj
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kennytm committed May 30, 2018
2 parents 7bf60b7 + c5ee3b6 commit c296b6b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {

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

let ret = io::copy(&mut reader, &mut writer)?;
set_permissions(to, perm)?;
writer.set_permissions(perm)?;
Ok(ret)
}

#[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 fs::File;
use sync::atomic::{AtomicBool, Ordering};

// Kernel prior to 4.5 don't have copy_file_range
Expand Down Expand Up @@ -907,14 +907,14 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
// Try again with fallback method
assert_eq!(written, 0);
let ret = io::copy(&mut reader, &mut writer)?;
set_permissions(to, perm)?;
writer.set_permissions(perm)?;
return Ok(ret)
},
_ => return Err(err),
}
}
}
}
set_permissions(to, perm)?;
writer.set_permissions(perm)?;
Ok(written)
}

0 comments on commit c296b6b

Please sign in to comment.