From: Jacob Bachmeyer Date: Fri, 28 Oct 2022 03:59:19 +0000 (-0500) Subject: Factor scanning loop out of directory_keyrings X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=303914d0e7e69a2bf0de4eae221af5fc5af7bdb4;p=gatekeeper.git Factor scanning loop out of directory_keyrings This allows the same loop to be used to support other per-directory items. --- diff --git a/gatekeeper.pl b/gatekeeper.pl index f5007f8..471685f 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -873,31 +873,43 @@ sub verify_clearsigned_message { # - Package configuration access # -=item @keyrings = directory_keyrings ( $directory ) +=item @files = directory_configuration_files ( $file, $directory ) -Return list of keyrings present in package configuration and applicable to -DIRECTORY, which is a relative name beginning with the appropriate package. +Return list of FILEs applicable to DIRECTORY. The rule used is that each +FILE applies to its own directory and is inherited by all subdirectories. =cut -sub directory_keyrings { +sub directory_configuration_files { + my $file = shift; my $directory = shift; - my @keyrings; my @candidates; for (my @directory = File::Spec::Unix->splitdir($directory); @directory; pop @directory) { push @candidates, File::Spec->catfile - ($package_config_base, @directory, 'pubring.gpg') } - push @candidates, File::Spec->catfile($package_config_base, 'pubring.gpg'); + ($package_config_base, @directory, $file) } + push @candidates, File::Spec->catfile($package_config_base, $file); - foreach my $keyring (@candidates) { - if (-f $keyring) { - ftp_syslog('debug', "DEBUG: found keyring $keyring") if DEBUG; - push @keyrings, $keyring; - } + return grep -f $_ && -r _ && -s _, @candidates; +} + +=item @keyrings = directory_keyrings ( $directory ) + +Return list of keyrings present in package configuration and applicable to +DIRECTORY, which is a relative name beginning with the appropriate package. + +=cut + +sub directory_keyrings { + my $directory = shift; + + my @keyrings = directory_configuration_files('pubring.gpg', $directory); + + if (DEBUG) { + ftp_syslog('debug', "DEBUG: found keyring $_") for @keyrings; } return @keyrings;