Add check for existence when removing a symlink
authorJacob Bachmeyer <jcb@gnu.org>
Wed, 9 Nov 2022 00:45:56 +0000 (18:45 -0600)
committerJacob Bachmeyer <jcb@gnu.org>
Wed, 9 Nov 2022 00:45:56 +0000 (18:45 -0600)
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
testsuite/gatekeeper.all/01_loose.exp
testsuite/lib/gatekeeper.exp

index acbf1b68b0eb69c5127b6ad103a0a53540ef0460..3822701564342c344a0de73921036e32e76a1e7b 100755 (executable)
@@ -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;
index 3d4d57f4c43ddd95417ef4826f441421e7e65a51..3f830e85ea49443fbc08f945d264fde350565a82 100644 (file)
@@ -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
index 9e6a7341ff03c3e888505baec91334f381ffb5c9..6c28f74956a302bf45a3c457bc094cc3edb965d1 100644 (file)
@@ -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