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.
This commit is contained in:
@@ -807,14 +807,14 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
|||||||
let perm = reader.metadata()?.permissions();
|
let perm = reader.metadata()?.permissions();
|
||||||
|
|
||||||
let ret = io::copy(&mut reader, &mut writer)?;
|
let ret = io::copy(&mut reader, &mut writer)?;
|
||||||
set_permissions(to, perm)?;
|
writer.set_permissions(perm)?;
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
||||||
use cmp;
|
use cmp;
|
||||||
use fs::{File, set_permissions};
|
use fs::File;
|
||||||
use sync::atomic::{AtomicBool, Ordering};
|
use sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
// Kernel prior to 4.5 don't have copy_file_range
|
// Kernel prior to 4.5 don't have copy_file_range
|
||||||
@@ -886,7 +886,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
|||||||
// Try again with fallback method
|
// Try again with fallback method
|
||||||
assert_eq!(written, 0);
|
assert_eq!(written, 0);
|
||||||
let ret = io::copy(&mut reader, &mut writer)?;
|
let ret = io::copy(&mut reader, &mut writer)?;
|
||||||
set_permissions(to, perm)?;
|
writer.set_permissions(perm)?;
|
||||||
return Ok(ret)
|
return Ok(ret)
|
||||||
},
|
},
|
||||||
_ => return Err(err),
|
_ => return Err(err),
|
||||||
@@ -894,6 +894,6 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_permissions(to, perm)?;
|
writer.set_permissions(perm)?;
|
||||||
Ok(written)
|
Ok(written)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user