Skip to content
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

chgrp: accept group ID argument #798

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions bin/chgrp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

my $Program = basename($0);
my ($VERSION) = '1.2';
my ($VERSION) = '1.3';

my $warnings = 0;

Expand Down Expand Up @@ -54,6 +54,9 @@ usage() unless @ARGV > 1;
my $group = shift;

my $gid = getgrnam $group;
unless (defined $gid) {
$gid = $group if $group =~ m/\A[0-9]+\z/;
}
unless (defined $gid) {
warn "$Program: '$group' is an invalid group\n";
exit EX_FAILURE;
Expand Down Expand Up @@ -100,11 +103,14 @@ sub modify_file {
$warnings++;
return;
}
my $uid = (stat $file) [4] or do {

my @st = stat $file;
unless (@st) {
warn "$Program: failed to stat '$file': $!\n";
$warnings++;
return;
};
my $uid = $st[4];
unless (chown $uid, $gid, $file) {
warn "$Program: '$file': $!\n";
$warnings++;
Expand Down Expand Up @@ -133,7 +139,7 @@ options is the new group.
=head2 OPTIONS

I<chgrp> accepts the options described below. The options I<-L>,
I<-H> and I<-P> are mutally exclusive, and only the last given
I<-H> and I<-P> are mutually exclusive, and only the last given
option will be honoured. All of I<-L>, I<-H> and I<-P> require the
I<-R> option to be set first.

Expand Down
Loading