1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:24:58 +00:00

chown+chgrp: Add --no-dereference option

This option will change the ownership of the symlink rather than the
file it points to.
This commit is contained in:
circl 2021-12-31 19:28:24 +01:00 committed by Andreas Kling
parent 63760603f3
commit 4b40d2cc07
2 changed files with 24 additions and 11 deletions

View file

@ -17,9 +17,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
const char* gid_arg = nullptr;
const char* path = nullptr;
bool dont_follow_symlinks = false;
Core::ArgsParser args_parser;
args_parser.set_general_help("Change the owning group for a file or directory.");
args_parser.add_option(dont_follow_symlinks, "Don't follow symlinks", "no-dereference", 'h');
args_parser.add_positional_argument(gid_arg, "Group ID", "gid");
args_parser.add_positional_argument(path, "Path to file", "path");
args_parser.parse(arguments);
@ -43,7 +45,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
new_gid = group->gr_gid;
}
TRY(Core::System::chown(path, -1, new_gid));
if (dont_follow_symlinks) {
TRY(Core::System::lchown(path, -1, new_gid));
} else {
TRY(Core::System::chown(path, -1, new_gid));
}
return 0;
}