-
-
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
fix #4767: chown -v 0 nf
isn't showing a message
#4768
fix #4767: chown -v 0 nf
isn't showing a message
#4768
Conversation
…ge a non existing file.
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.
Cool! I like it, but I think we can do a bit of cleanup.
src/uu/chgrp/src/chgrp.rs
Outdated
@@ -21,16 +21,22 @@ use std::os::unix::fs::MetadataExt; | |||
static ABOUT: &str = help_about!("chgrp.md"); | |||
const USAGE: &str = help_usage!("chgrp.md"); | |||
|
|||
fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, IfFrom)> { | |||
fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, String, IfFrom)> { |
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.
Maybe it makes sense to make a struct for the (Option<u32>, Option<u32>, String, IfFrom)
? That would make it a bit easier to read (and make the types shorter).
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.
Also the String
might need to be an OsString
if it can contain invalid utf-8.
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.
The raw_owner: String
is constructed by either:
matches.get_one::<String>( ... )
or- format of
entries::uid2usr(uid).unwrap_or_else(|_| uid.to_string())
I don't know if these two functions are robust enough to invalid utf-8.
If not, it might imply to refactor at least uucore/*/perms.rs
, uu/*/chown.rs
, uu/*/chgrp.rs
. Then it should be useful to open a dedicated issue for it.
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.
I refactored (Option<u32>, Option<u32>, String, IfFrom)
to a struct GidUidOwnerFilter
.
tests/by-util/test_chown.rs
Outdated
// TODO: uncomment once "failed to change ownership of '{}' to {}" added to stdout | ||
// result.stderr_contains("retained as"); | ||
result.stdout_contains(format!( | ||
"failed to change ownership of 'not_existing' to {user_name}" |
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.
Interesting that this message is different from the one that was commented out. Was that just a mistake?
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.
You could also add this assertion to the rest of the expression:
scene
.ucmd()
...
.fails()
.stdout_contains(...);
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.
The actual test tests a non existing file with verbose flag:
chown -v 0 nf
The string "retained as" is printed by the command:
touch f
chown -v --from=42 43 f
These two cases came from the GNU test suite: tests/chown/basic.sh
I guess you know but the gnu test still fails with:
|
There are two tests failing in # Make sure the correct diagnostic is output
# Note we output a name even though an id was specified.
chown -v --from=42 43 f > out || fail=1
printf "ownership of 'f' retained as $(id -nu)\n" > exp
compare exp out || fail=1
# Ensure diagnostics work for non existent files.
returns_ 1 chown -v 0 nf > out || fail=1
printf "failed to change ownership of 'nf' to 0\n" > exp
compare exp out || fail=1 This PR fix the second test: "failed to change ownership of" So when theses two PRs will be merged to main, the gnu test will pass. |
GNU testsuite comparison:
|
Thanks for your PR :) |
This PR modify
chown
to print a message to stdout when the file doesn't exist.It's a fix for #4767 .
The following cases are implemented:
To access the owner as specified by the user in the command, I had to modify the signature of the tuple returns by
parse_gid_uid_and_filter
and add a field in the structChownExecutor
.Note: the first part of the GNU tests/chown/basic is expected to fail (ownership of 'f' retained as root) but the rest is not.