mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
chown: Add support for multiple file paths
This commit is contained in:
parent
bd48d9521a
commit
7b7c9a2194
1 changed files with 8 additions and 6 deletions
|
@ -21,14 +21,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::pledge("stdio rpath chown"));
|
||||
|
||||
String spec;
|
||||
String path;
|
||||
Vector<StringView> paths;
|
||||
bool dont_follow_symlinks = false;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.set_general_help("Change the ownership of a file or directory.");
|
||||
args_parser.add_option(dont_follow_symlinks, "Don't follow symlinks", "no-dereference", 'h');
|
||||
args_parser.add_positional_argument(spec, "User and group IDs", "USER[:GROUP]");
|
||||
args_parser.add_positional_argument(path, "Path to file", "PATH");
|
||||
args_parser.add_positional_argument(paths, "Paths to files", "PATH");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
uid_t new_uid = -1;
|
||||
|
@ -66,10 +66,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
}
|
||||
|
||||
if (dont_follow_symlinks) {
|
||||
TRY(Core::System::lchown(path, new_uid, new_gid));
|
||||
} else {
|
||||
TRY(Core::System::chown(path, new_uid, new_gid));
|
||||
for (auto path : paths) {
|
||||
if (dont_follow_symlinks) {
|
||||
TRY(Core::System::lchown(path, new_uid, new_gid));
|
||||
} else {
|
||||
TRY(Core::System::chown(path, new_uid, new_gid));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue