-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cp: fix -p to not preserve xattrs by default #9708
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
Open
AnarchistHoneybun
wants to merge
14
commits into
uutils:main
Choose a base branch
from
AnarchistHoneybun:bug/cp-preserve-xattr-9704
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
68522d9
cp: fix -p to not preserve xattrs by default
AnarchistHoneybun c46688b
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun 655cf52
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun e5066d8
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun b0d6c49
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun 628e18d
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun 92b4ec2
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun f0366d3
cp: preserve ACL xattrs with -p while excluding others
AnarchistHoneybun 7305e51
opnbsd isn't supported
sylvestre f7969d7
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun afedc07
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun 78b5b5f
tests: use at_and_ucmd macro and remove redundant cfg guards
AnarchistHoneybun 1b8c342
Merge branch 'main' into bug/cp-preserve-xattr-9704
sylvestre 5d0ec1c
Merge branch 'main' into bug/cp-preserve-xattr-9704
AnarchistHoneybun 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
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -1773,6 +1773,112 @@ fn test_cp_preserve_xattr() { | |
| } | ||
| } | ||
|
|
||
| // -p preserves mode, ownership, and timestamps, but not xattrs | ||
| // xattrs require explicit --preserve=xattr or -a | ||
| #[test] | ||
| #[cfg(all( | ||
| unix, | ||
| not(any(target_os = "android", target_os = "macos", target_os = "openbsd")) | ||
| ))] | ||
| fn test_cp_preserve_default_no_xattr() { | ||
| use std::process::Command; | ||
| use uutests::util::compare_xattrs; | ||
|
|
||
| let scene = TestScenario::new(util_name!()); | ||
|
||
| let at = &scene.fixtures; | ||
|
|
||
| let source_file = "source_with_xattr"; | ||
| let dest_file_p = "dest_with_p_flag"; | ||
| let dest_file_explicit = "dest_with_explicit_xattr"; | ||
|
|
||
| at.touch(source_file); | ||
|
|
||
| // set xattr on source | ||
| let xattr_key = "user.test_preserve"; | ||
| let xattr_value = "test_value"; | ||
| match Command::new("setfattr") | ||
| .args([ | ||
| "-n", | ||
| xattr_key, | ||
| "-v", | ||
| xattr_value, | ||
| &at.plus_as_string(source_file), | ||
| ]) | ||
| .status() | ||
| .map(|status| status.code()) | ||
| { | ||
| Ok(Some(0)) => {} | ||
| Ok(_) => { | ||
| println!("test skipped: setfattr failed"); | ||
| return; | ||
| } | ||
| Err(e) => { | ||
| println!("test skipped: setfattr failed with {e}"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // verify xattr was set | ||
| let getfattr_output = Command::new("getfattr") | ||
| .args([&at.plus_as_string(source_file)]) | ||
| .output() | ||
| .expect("failed to run getfattr"); | ||
|
|
||
| assert!( | ||
| getfattr_output.status.success(), | ||
| "getfattr failed: {}", | ||
| String::from_utf8_lossy(&getfattr_output.stderr) | ||
| ); | ||
|
|
||
| let stdout = String::from_utf8_lossy(&getfattr_output.stdout); | ||
| assert!( | ||
| stdout.contains(xattr_key), | ||
| "xattr not found on source: {xattr_key}" | ||
| ); | ||
|
|
||
| // -p should not preserve xattrs | ||
| scene | ||
| .ucmd() | ||
| .args(&[ | ||
| "-p", | ||
| &at.plus_as_string(source_file), | ||
| &at.plus_as_string(dest_file_p), | ||
| ]) | ||
| .succeeds() | ||
| .no_output(); | ||
|
|
||
| // xattrs should not be copied | ||
| assert!( | ||
| !compare_xattrs(&at.plus(source_file), &at.plus(dest_file_p)), | ||
| "cp -p incorrectly preserved xattrs" | ||
| ); | ||
|
|
||
| // mode, ownership, and timestamps should be preserved | ||
| #[cfg(not(any(target_os = "freebsd", target_os = "macos")))] | ||
|
||
| { | ||
| let metadata_src = at.metadata(source_file); | ||
| let metadata_dst = at.metadata(dest_file_p); | ||
| assert_metadata_eq!(metadata_src, metadata_dst); | ||
| } | ||
|
|
||
| // --preserve=xattr should explicitly preserve xattrs | ||
| scene | ||
| .ucmd() | ||
| .args(&[ | ||
| "--preserve=xattr", | ||
| &at.plus_as_string(source_file), | ||
| &at.plus_as_string(dest_file_explicit), | ||
| ]) | ||
| .succeeds() | ||
| .no_output(); | ||
|
|
||
| // xattrs should be copied | ||
| assert!( | ||
| compare_xattrs(&at.plus(source_file), &at.plus(dest_file_explicit)), | ||
| "cp --preserve=xattr did not preserve xattrs" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(all(target_os = "linux", not(feature = "feat_selinux")))] | ||
| fn test_cp_preserve_all_context_fails_on_non_selinux() { | ||
|
|
||
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.
clippy warning here :)
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.
for some reason this doesn't come up for me when I locally run it, should I be adding the openbsd flag here too, that we have on :1722?