Skip to content

Commit 9b6940d

Browse files
committed
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.
1 parent 2408095 commit 9b6940d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libstd/sys/unix/fs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -807,14 +807,14 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
807807
let perm = reader.metadata()?.permissions();
808808

809809
let ret = io::copy(&mut reader, &mut writer)?;
810-
set_permissions(to, perm)?;
810+
writer.set_permissions(perm)?;
811811
Ok(ret)
812812
}
813813

814814
#[cfg(any(target_os = "linux", target_os = "android"))]
815815
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
816816
use cmp;
817-
use fs::{File, set_permissions};
817+
use fs::File;
818818
use sync::atomic::{AtomicBool, Ordering};
819819

820820
// Kernel prior to 4.5 don't have copy_file_range
@@ -886,14 +886,14 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
886886
// Try again with fallback method
887887
assert_eq!(written, 0);
888888
let ret = io::copy(&mut reader, &mut writer)?;
889-
set_permissions(to, perm)?;
889+
writer.set_permissions(perm)?;
890890
return Ok(ret)
891891
},
892892
_ => return Err(err),
893893
}
894894
}
895895
}
896896
}
897-
set_permissions(to, perm)?;
897+
writer.set_permissions(perm)?;
898898
Ok(written)
899899
}

0 commit comments

Comments
 (0)