mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:47:35 +00:00
LibCore+chown: Return ErrorOr<Optional<...>> for getgrnam and getpwnam
This patch returns an empty Optional<...> instead of an Error for Core::System::getgrname and Core::System::getpwnam if we can't find a matching group or user entry. It also updates the 'chown' utility to support this new behavior.
This commit is contained in:
parent
ab324c1dae
commit
7772309169
3 changed files with 16 additions and 8 deletions
|
@ -42,7 +42,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
new_uid = number.value();
|
||||
} else {
|
||||
auto passwd = TRY(Core::System::getpwnam(parts[0]));
|
||||
new_uid = passwd.pw_uid;
|
||||
if (!passwd.has_value()) {
|
||||
warnln("Unknown user '{}'", parts[0]);
|
||||
return 1;
|
||||
}
|
||||
new_uid = passwd->pw_uid;
|
||||
}
|
||||
|
||||
if (parts.size() == 2) {
|
||||
|
@ -51,7 +55,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
new_gid = number.value();
|
||||
} else {
|
||||
auto group = TRY(Core::System::getgrnam(parts[1]));
|
||||
new_gid = group.gr_gid;
|
||||
if (!group.has_value()) {
|
||||
warnln("Unknown group '{}'", parts[1]);
|
||||
return 1;
|
||||
}
|
||||
new_gid = group->gr_gid;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue