Skip to content
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
13 changes: 9 additions & 4 deletions bin/chown
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

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

my $rc = EX_SUCCESS;

Expand Down Expand Up @@ -54,6 +54,9 @@ usage() unless @ARGV;
my ($owner, $group) = split /:/ => $mode, 2;

my $uid = getpwnam $owner;
unless (defined $uid) {
$uid = $owner if $owner =~ m/\A[0-9]+\z/;
}
unless (defined $uid) {
warn "$Program: invalid user: '$owner'\n";
exit EX_FAILURE;
Expand Down Expand Up @@ -103,11 +106,13 @@ sub modify_file {
return;
}
unless (defined $group) {
$gid = (stat $file)[5] or do {
my @st = stat $file;
unless (@st) {
warn "$Program: failed to stat '$file': $!\n";
$rc = EX_FAILURE;
return;
};
}
$gid = $st[5];
}
unless (chown $uid, $gid, $file) {
warn "$Program: '$file': $!\n";
Expand Down Expand Up @@ -137,7 +142,7 @@ is changed as well.
=head2 OPTIONS

I<chown> 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