From 428b876b24600f88242a83440f609aabaa7632fd Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Tue, 8 Nov 2022 18:45:56 -0600 Subject: [PATCH] Add check for existence when removing a symlink While the later check to verify that the symlink to be removed actually is a symlink will also fail if no such file exists, this produces a message that confusingly reports a refusal to remove a non-symlink file. --- gatekeeper.pl | 3 +++ testsuite/gatekeeper.all/01_loose.exp | 20 ++++++++++++++++++++ testsuite/lib/gatekeeper.exp | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/gatekeeper.pl b/gatekeeper.pl index acbf1b6..3822701 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -2470,6 +2470,9 @@ sub execute_commands { } elsif ($step->[0] eq 'rmsymlink') { my $abslinkname = File::Spec->catfile($Public_dir, @directory, $step->[1]); + throw processing_error => command => $step, + summary => "symlink $step->[1] was not found" + unless -e $abslinkname; throw processing_error => command => $step, summary => "refusing to remove a non-symlink file" unless -l $abslinkname; diff --git a/testsuite/gatekeeper.all/01_loose.exp b/testsuite/gatekeeper.all/01_loose.exp index 3d4d57f..3f830e8 100644 --- a/testsuite/gatekeeper.all/01_loose.exp +++ b/testsuite/gatekeeper.all/01_loose.exp @@ -633,6 +633,26 @@ check_loose_directive "error: remove symlink with too many parameters" { foo@example.org foo@example.gnu.org foo@example.net } +check_loose_directive "error: remove non-existent symlink" { + directive { + version 1.2 + directory foo + rmsymlink foo-latest.bin + } dsig { good 13 1000 } +} initial-files { + pub { foo/foo-1.0.bin { good 05 1000 } } +} file-tree { + { incoming stage archive } empty {} + { in-stage } files { .foo.directive.asc } + { pub } files { foo/foo-1.0.bin } +} log { + action,rm-symlink-failure,not-found \ + "rmsymlink command targeting non-existent file rejected" +} email-to { + ftp-upload-script@gnu.org ftp-upload-report@gnu.org + foo@example.org foo@example.gnu.org foo@example.net +} + check_loose_directive "error: remove file as if symlink" { directive { version 1.2 diff --git a/testsuite/lib/gatekeeper.exp b/testsuite/lib/gatekeeper.exp index 9e6a734..6c28f74 100644 --- a/testsuite/lib/gatekeeper.exp +++ b/testsuite/lib/gatekeeper.exp @@ -521,6 +521,13 @@ proc analyze_log { base_dir name assess } { # include a file name relative to the test base exp_continue } + -re {^gatekeeper\[[0-9]+\]: \(Test\) \[EX\]\ + symlink [^ ]+ was not found} { + # from execute_commands, when an item to be removed is + # not a symlink after all + set A(action,rm-symlink-failure,not-found) 1 + exp_continue + } -re {^gatekeeper\[[0-9]+\]: \(Test\) \[EX\]\ refusing to remove a non-symlink file} { # from execute_commands, when an item to be removed is -- 2.25.1