warn if a hook is named like one but not executable and if a hook is executable but not named like one

This commit is contained in:
Johannes Schauer Marin Rodrigues 2023-01-16 07:55:27 +01:00
parent 0b7188ce32
commit ea2b57870b
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -4526,14 +4526,28 @@ sub main() {
opendir(my $dh, $opt_value) opendir(my $dh, $opt_value)
or error "Can't opendir($opt_value): $!"; or error "Can't opendir($opt_value): $!";
while (my $entry = readdir $dh) { while (my $entry = readdir $dh) {
# skip the "." and ".." entries
next if $entry eq ".";
next if $entry eq "..";
my $found = 0;
foreach foreach
my $hook ('setup', 'extract', 'essential', 'customize') { my $hook ('setup', 'extract', 'essential', 'customize') {
if ($entry =~ m/^\Q$hook\E/ and -x "$opt_value/$entry") { if ($entry =~ m/^\Q$hook\E/) {
if (-x "$opt_value/$entry") {
push @{ $scripts{$hook} }, "$opt_value/$entry"; push @{ $scripts{$hook} }, "$opt_value/$entry";
$count += 1; $count += 1;
$found = 1;
} else {
warning("$opt_value/$entry is named like a "
. "hook but not executable");
} }
} }
} }
if (!$found && -x "$opt_value/$entry") {
warning("$opt_value/$entry: is executable "
. "but not prefixed with a hook name");
}
}
closedir($dh); closedir($dh);
if ($count == 0) { if ($count == 0) {
warning "No executable hook scripts found in $opt_value"; warning "No executable hook scripts found in $opt_value";