Skip to content

Commit 0fd0e9c

Browse files
authored
chgrp: (#977)
* Similar to commit 471e64b for bin/chown * Fail early if the 1st (group) argument is an empty string to avoid unnecessary getgrnam('') call * style: forward declaration of modify_file() is not needed if the method is called with parens * style: move default exit() statement above the subroutine declarations, as done in other scripts
1 parent bee24d7 commit 0fd0e9c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

bin/chgrp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ License: perl
1111
1212
=cut
1313

14-
15-
1614
use strict;
1715

1816
use File::Basename qw(basename);
@@ -53,6 +51,10 @@ usage() unless @ARGV > 1;
5351

5452
my $group = shift;
5553

54+
if (length($group) == 0) {
55+
warn "$Program: '' is an invalid group\n";
56+
exit EX_FAILURE;
57+
}
5658
my $gid = getgrnam $group;
5759
unless (defined $gid) {
5860
$gid = $group if $group =~ m/\A[0-9]+\z/;
@@ -65,18 +67,17 @@ unless (defined $gid) {
6567
my %ARGV;
6668
%ARGV = map {$_ => 1} @ARGV if $options {H};
6769

68-
sub modify_file;
69-
7070
if (exists $options {R}) {
7171
# Recursion.
7272
require File::Find;
7373
File::Find::find (\&modify_file, @ARGV);
7474
}
7575
else {
7676
foreach my $file (@ARGV) {
77-
modify_file $file;
77+
modify_file($file);
7878
}
7979
}
80+
exit ($warnings ? EX_FAILURE : EX_SUCCESS);
8081

8182
# File::Find is weird. If called with a directory, it will call
8283
# the sub with "." as file name, while having chdir()ed to the
@@ -111,8 +112,6 @@ sub modify_file {
111112
}
112113
}
113114

114-
exit ($warnings ? EX_FAILURE : EX_SUCCESS);
115-
116115
__END__
117116
118117
=pod

0 commit comments

Comments
 (0)