From 36ba0ba7fe3e3077b3eb9ad6ed5b5b6414964545 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Sat, 15 Oct 2022 23:02:56 -0500 Subject: [PATCH] Revise main packet processing loop to use new gather_packets result --- gatekeeper.pl | 65 +++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 54c762b..e6752db 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -1955,53 +1955,42 @@ sub cleanup { # - Main execution path # -my @incoming = gather_packets($incoming_dir, $incoming_tmp); - -# Temporary scaffolding to convert the new values returned by scan_incoming -# to the old format. -foreach my $cell (@incoming) { - next if ref $cell eq 'HASH'; # cell is old format - - if (3 == scalar @$cell) { # an upload triplet - my $directive; my $sig; my $upload; - foreach (@$cell) { - if (m/[.]directive[.]asc$/) { $directive = $_ } - elsif (m/[.]sig$/) { $sig = $_ } - else { $upload = $_ } - } - $cell = {directive => $directive, sig => $sig, - upload => $upload, directive_only => 0} - } elsif (1 == scalar @$cell) {# loose directive - $cell = {directive => $cell->[0], sig => '', - upload => '', directive_only => 1} - } -} -# End temporary scaffolding. +my @packets = gather_packets($incoming_dir, $incoming_tmp); # we've moved the files to work on to a new directory. chdir ($incoming_tmp) or ftp_abort("FATAL: chdir($incoming_tmp) failed: $!"); -for my $files (@incoming) { # each list element is a hash reference. - ftp_syslog('info',"found directive: $files->{directive}\n"); - # if we die processing a triplet, the eval allows us to move - # onto the next triplet. - eval { +foreach my $packet (@packets) { # each list element is an array reference + ftp_syslog('info',"found directive: $packet->[0]\n"); + + # scaffolding to be cleaned up as the internal API is improved + my $directive_only = (1 == scalar @$packet); + my $directive_file = $packet->[0]; + my $upload_file = ''; my $sig_file = ''; + + eval { # trap exceptions encountered while processing a packet + unless ($directive_only) { + foreach (@{$packet}[1..$#$packet]) { + if (m/[.]sig$/) { $sig_file =$_ } else { $upload_file = $_ } + } + } # set up the %info variable - my $retval = read_directive_file ($files->{"directive"}, - $files->{"upload"}, - $files->{"directive_only"}); + my $retval = read_directive_file ($directive_file, + $upload_file, + $directive_only); if ($retval == 0) { # do the work - execute_commands($files,%info); + execute_commands({directive => $directive_file, upload => $upload_file, + sig => $sig_file, directive_only => $directive_only}, + %info); # report success - if (!$files->{"directive_only"}) { - success_upload($files->{"sig"}, $files->{"upload"}, - $files->{"directive"}); + if (!$directive_only) { + success_upload($sig_file, $upload_file, $directive_file); } else { - success_directive($files->{directive}); + success_directive($directive_file); } } }; @@ -2009,16 +1998,16 @@ for my $files (@incoming) { # each list element is a hash reference. if $@; # clean up files if we abort while processing a triplet - cleanup ($files->{"sig"}, $files->{"upload"}, $files->{"directive"}) + cleanup ($sig_file, $upload_file, $directive_file) if ($@); # clear out the current package that we just finished processing undef %info; } -if ((scalar @incoming) == 0) { +if ((scalar @packets) == 0) { ftp_syslog('info', "No files found for processing."); } else { ftp_syslog('info', "Processing complete: " - .(scalar @incoming)." uploads processed."); + .(scalar @packets)." uploads processed."); system("/usr/local/bin/generate-ftpindex") unless IN_TEST_MODE; ftp_syslog('info', "Updated ftpindex"); -- 2.25.1