foreach (@ARGV) {
usagedie() if (!-f || !-d);
}
####
usagedie() if grep not( -f or -d ), @ARGV;
##
##
find(\&fileop, $opts{'directory'}) unless @ARGV;
find(\&fileop, @ARGV) if @ARGV;
##
##
find( \&fileop, @ARGV ? @ARGV : $opt_directory );
##
##
sub fileop {
#set the right permissions based on if a file or a directory
#only set permissions of the mode is set
chmod oct($opts{'filemode'}), $_ if -f && $opts{'filemode'};
chmod oct($opts{'dirmode'}), $_ if -d && $opts{'dirmode'};
print $File::Find::name . "\n" if $opts{'verbose'} && (-f || -d);
}
##
##
sub fileop {
if( -f and $opt_filemode ) {
chmod oct( $opt_filemode ), $_;
}
elsif( -d and $opt_dirmode ) {
chmod oct( $opt_dirmode ), $_;
}
else {
return; # avoid falling thru to print()
}
print $File::Find::name, "\n" if $opt_verbose;
}
##
##
sub check_perm {
my ( $mode, $perm ) = @_;
if( defined $perm ) {
return ( $perm =~ /^[0-7]{3}$/ )
? oct( $perm )
: die "Malformed $mode mode $perm\n";
}
return;
}
$opt_filemode = check_perm file => $opt_filemode;
$opt_dirmode = check_perm directory => $opt_dirmode;