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

chmod: list filename in warning if chmod() fails #813

Merged
merged 1 commit into from
Nov 15, 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
27 changes: 14 additions & 13 deletions bin/chmod
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,31 @@ License: perl

=cut


use strict;

my ($VERSION) = '1.2';
use File::Basename qw(basename);

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

my $warnings = 0;

# Print a usuage message on a unknown option.
# Requires my patch to Getopt::Std of 25 Feb 1999.
$SIG {__WARN__} = sub {
if (substr ($_ [0], 0, 14) eq "Unknown option") {die "Usage"};
require File::Basename;
$0 = File::Basename::basename ($0);
$warnings = 1;
warn "$0: @_";
warn "$Program: @_";
};

$SIG {__DIE__} = sub {
require File::Basename;
$0 = File::Basename::basename ($0);
if (substr ($_ [0], 0, 5) eq "Usage") {
die <<EOF;
$0 (Perl bin utils) $VERSION
$0 [-R [-H | -L | -P]] mode file [files ...]
$Program (Perl bin utils) $VERSION
$Program [-R [-H | -L | -P]] mode file [files ...]
EOF
}
die "$0: @_";
die "$Program: @_";
};

# Get the options.
Expand All @@ -47,7 +45,10 @@ while (@ARGV && $ARGV [0] =~ /^-/) {
my $opt = reverse shift;
chop $opt;
last if ($opt eq '-');
die "Usage" unless $opt =~ /^[RHLP]+$/;
unless ($opt =~ /^[RHLP]+$/) {
warn "$Program: invalid option -- $opt\n";
die 'Usage';
}
local $_;
while (length ($_ = chop $opt)) {
/R/ && do {$options {R} = 1; next};
Expand Down Expand Up @@ -115,7 +116,7 @@ sub modify_file {
$realmode = mod($mode, $file) or
die "invalid mode: $mode\n";
}
chmod oct ($realmode), $file or warn "$!\n";
chmod oct ($realmode), $file or warn "failed to change mode for '$file': $!\n";
}

exit $warnings;
Expand Down Expand Up @@ -342,7 +343,7 @@ options is permission the files should be given.
=head2 OPTIONS

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

Expand Down
Loading