1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-21 12:55:07 +00:00

chown: Add support for multiple file paths

This commit is contained in:
Tim Schumacher 2022-07-25 16:54:52 +02:00 committed by Linus Groh
parent bd48d9521a
commit 7b7c9a2194

View file

@ -21,14 +21,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio rpath chown")); TRY(Core::System::pledge("stdio rpath chown"));
String spec; String spec;
String path; Vector<StringView> paths;
bool dont_follow_symlinks = false; bool dont_follow_symlinks = false;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.set_general_help("Change the ownership of a file or directory."); 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_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(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); args_parser.parse(arguments);
uid_t new_uid = -1; uid_t new_uid = -1;
@ -66,11 +66,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
} }
} }
for (auto path : paths) {
if (dont_follow_symlinks) { if (dont_follow_symlinks) {
TRY(Core::System::lchown(path, new_uid, new_gid)); TRY(Core::System::lchown(path, new_uid, new_gid));
} else { } else {
TRY(Core::System::chown(path, new_uid, new_gid)); TRY(Core::System::chown(path, new_uid, new_gid));
} }
}
return 0; return 0;
} }