diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-05-31 22:17:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-31 22:17:14 +0200 |
| commit | af4acbe5e7e2295c42e50c83b029f7c4ce3b0931 (patch) | |
| tree | 800b5512a2842c62cf6ba790ec108f536878a9ad /src/libstd/sys | |
| parent | 8efecc110266dd614503f0a8b9c1a31d5b52a144 (diff) | |
| parent | c5ee3b6df1db2c4410b0e8d7a80a2885cf5628f1 (diff) | |
| download | rust-af4acbe5e7e2295c42e50c83b029f7c4ce3b0931.tar.gz rust-af4acbe5e7e2295c42e50c83b029f7c4ce3b0931.zip | |
Rollup merge of #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.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index c4d94259bd6..c4092dcd388 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -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")) @@ -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 @@ -907,7 +907,7 @@ 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), @@ -915,6 +915,6 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { } } } - set_permissions(to, perm)?; + writer.set_permissions(perm)?; Ok(written) } |
