From 302990ae72f62a258c8196c5484e81f3f822a9d9 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Thu, 20 Oct 2022 23:25:53 -0500 Subject: [PATCH] Revise execute_commands to use new operation list --- gatekeeper.pl | 56 ++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index b4dbcf5..18e986c 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -1928,28 +1928,21 @@ sub execute_commands { my $files = shift; my %info = @_; - # This is ugly but necessary. - # Delete all info entries that are NOT hashes with an 'order' value - # (and hence would mess up the foreach loop below). Make a backup of - # the hash first so we can feed the real thing to check_files & install_files + # Keep the hash as temporary scaffolding for check_files & install_files my %originfo = %info; - delete($info{directory}); - delete($info{email}); - delete($info{package}); - delete($info{version}); - delete($info{'replace'}); ftp_abort("invalid internal operation list") unless $oplist->[0][0] eq 'header'; my $header = $oplist->[0][1]; - my $destdir = "$destfinal/$originfo{directory}"; - foreach my $key (sort { $info{$a}{order} <=> $info{$b}{order} } keys %info) { - if ($key eq 'filename') { + my $destdir = "$destfinal/$header->{directory}"; + foreach my $step (@{$oplist}[1..$#$oplist]) { # skip the header + if ($step->[0] eq 'install') { check_files($files,%originfo); install_files($files,%originfo); - } elsif ($key =~ /^symlink-(.*)/) { - my $target = $1; + } elsif ($step->[0] eq 'symlink') { + my $target = $step->[1]; + my $linkname = $step->[2]; # Get current working dir my $cwd = getcwd; # Make sure there are no double dots in the path, and that it is absolute. @@ -1959,35 +1952,38 @@ sub execute_commands { # Now untaint the getcwd output $cwd =~ /^(.*)$/; $cwd = $1; - chomp($cwd); # change to destination dir chdir($destdir); # if the symlink already exists, remove it - if (-l $info{$key}{link}) { - unlink($info{$key}{link}) - or fatal("removal of symlink $info{$key}{link} failed: $!",1); + if (-l $linkname) { + unlink $linkname + or fatal("removal of symlink $linkname failed: $!",1); } # symlink away! - symlink("$target",$info{$key}{link}) - or fatal("creation of symlink $info{$key}{link} " + symlink $target, $linkname + or fatal("creation of symlink $linkname " ."to $target in $destdir failed: $!",1); # go back to current working dir ftp_syslog('info', "added symlink $destdir/" - .$info{$key}{link} . " pointing to $destdir/$target"); + .$linkname . " pointing to $destdir/$target"); chdir($cwd) or fatal("chdir to $cwd failed: $!",1); - } elsif ($key =~ /^rmsymlink-(.*)/) { + } elsif ($step->[0] eq 'rmsymlink') { fatal("refusing to remove a non-symlink file",1) - unless -l "$destdir/$1"; - unlink("$destdir/$1") - or fatal("removal of symlink $1 failed: $!",1); - ftp_syslog('info', "removed symlink $destdir/$1"); - } elsif ($key =~ /^archive-(.*)/) { + unless -l "$destdir/$step->[1]"; + unlink("$destdir/$step->[1]") + or fatal("removal of symlink $step->[1] failed: $!",1); + ftp_syslog('info', "removed symlink $destdir/$step->[1]"); + } elsif ($step->[0] eq 'archive') { # We now also allow archiving entire directories - archive($destdir, $originfo{directory}, "$1.sig") - if (! -d "$destdir/$1"); - archive($destdir, $originfo{directory}, $1); + archive($destdir, $header->{directory}, $step->[1].'.sig') + unless -d "$destdir/$step->[1]"; + archive($destdir, $header->{directory}, $step->[1]); + } elsif (IN_TEST_MODE && $step->[0] eq 'no-op') { + # do nothing + } else { + ftp_abort("unknown internal operation: $step->[0]"); } } } -- 2.25.1