-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cp: --preserve should keep xattr #5834
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// | ||
// For the full copyright and license information, please view the LICENSE | ||
// file that was distributed with this source code. | ||
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs outfile uufs | ||
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs outfile uufs xattrs | ||
|
||
use crate::common::util::TestScenario; | ||
#[cfg(not(windows))] | ||
|
@@ -56,6 +56,8 @@ | |
static TEST_MOUNT_OTHER_FILESYSTEM_FILE: &str = "mount/DO_NOT_copy_me.txt"; | ||
#[cfg(unix)] | ||
static TEST_NONEXISTENT_FILE: &str = "nonexistent_file.txt"; | ||
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] | ||
use xattr; | ||
|
||
/// Assert that mode, ownership, and permissions of two metadata objects match. | ||
#[cfg(all(not(windows), not(target_os = "freebsd")))] | ||
|
@@ -3701,3 +3703,57 @@ | |
.fails() | ||
.stderr_is("cp: 'no-such/' is not a directory\n"); | ||
} | ||
|
||
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] | ||
fn compare_xattrs<P: AsRef<Path>>(path1: P, path2: P) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will update this code to use the one in after this one is merged |
||
let get_sorted_xattrs = |path: P| { | ||
xattr::list(path) | ||
.map(|attrs| { | ||
let mut attrs = attrs.collect::<Vec<_>>(); | ||
attrs.sort(); | ||
attrs | ||
}) | ||
.unwrap_or_else(|_| Vec::new()) | ||
}; | ||
|
||
get_sorted_xattrs(path1) == get_sorted_xattrs(path2) | ||
} | ||
|
||
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] | ||
#[test] | ||
fn test_acl_preserve() { | ||
use std::process::Command; | ||
|
||
let scene = TestScenario::new(util_name!()); | ||
let at = &scene.fixtures; | ||
let path1 = "a"; | ||
let path2 = "b"; | ||
let file = "a/file"; | ||
let file_target = "b/file"; | ||
at.mkdir(path1); | ||
at.mkdir(path2); | ||
at.touch(file); | ||
|
||
let path = at.plus_as_string(file); | ||
// calling the command directly. xattr requires some dev packages to be installed | ||
// and it adds a complex dependency just for a test | ||
match Command::new("setfacl") | ||
.args(["-m", "group::rwx", &path1]) | ||
.status() | ||
.map(|status| status.code()) | ||
{ | ||
Ok(Some(0)) => {} | ||
Ok(_) => { | ||
println!("test skipped: setfacl failed"); | ||
return; | ||
} | ||
Err(e) => { | ||
println!("test skipped: setfacl failed with {}", e); | ||
return; | ||
} | ||
} | ||
|
||
scene.ucmd().args(&["-p", &path, path2]).succeeds(); | ||
|
||
assert!(compare_xattrs(&file, &file_target)); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the expected behavior that the test doesn't fail if the changes in
cp.rs
are not applied?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, i am planning to fix mac and the tests once they land :)