mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cp: correctly copy mode, ownership, acl and context
Fix a mix-up between ownership and mode. The latter (mode / file permissions) can also be set on windows (which however only affects the read-only flag), while there doesn't seem to be a straight-forward way to change file ownership on windows. Copy the acl as well when copying the mode. This is a non-default feature and can be enabled with --features feat_acl, because it doesn't seem to work on CI. It is only available for unix so far. Copy the SELinux context if possible.
This commit is contained in:
parent
575fbd4cb7
commit
8b74562820
8 changed files with 303 additions and 51 deletions
|
@ -7,7 +7,7 @@ use std::fs::set_permissions;
|
|||
#[cfg(not(windows))]
|
||||
use std::os::unix::fs;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::fs::symlink_file;
|
||||
|
@ -1305,3 +1305,51 @@ fn test_copy_symlink_force() {
|
|||
.succeeds();
|
||||
assert_eq!(at.resolve_link("copy"), "file");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_no_preserve_mode() {
|
||||
use std::os::unix::prelude::MetadataExt;
|
||||
|
||||
use uucore::mode::get_umask;
|
||||
|
||||
const PERMS_ALL: u32 = 0o7777;
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch("file");
|
||||
set_permissions(at.plus("file"), PermissionsExt::from_mode(PERMS_ALL)).unwrap();
|
||||
ucmd.arg("file")
|
||||
.arg("dest")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
let umask = get_umask();
|
||||
// remove sticky bit, setuid and setgid bit; apply umask
|
||||
let expected_perms = PERMS_ALL & !0o7000 & !umask;
|
||||
assert_eq!(
|
||||
at.plus("dest").metadata().unwrap().mode() & 0o7777,
|
||||
expected_perms
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_preserve_mode() {
|
||||
use std::os::unix::prelude::MetadataExt;
|
||||
|
||||
const PERMS_ALL: u32 = 0o7777;
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch("file");
|
||||
set_permissions(at.plus("file"), PermissionsExt::from_mode(PERMS_ALL)).unwrap();
|
||||
ucmd.arg("file")
|
||||
.arg("dest")
|
||||
.arg("-p")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
assert_eq!(
|
||||
at.plus("dest").metadata().unwrap().mode() & 0o7777,
|
||||
PERMS_ALL
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue