From 1511d38bacae4f83c806169e78f51fdb4140bda7 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Tue, 22 Nov 2022 21:38:50 -0600 Subject: [PATCH] Preserve error string during rename checks at initialization The test file is unlinked if a rename call fails; this could reset $! to indicate success, so the initial value of $! is saved first. --- gatekeeper.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 81a6e1b..3921bab 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -685,8 +685,9 @@ BEGIN { or abort "FATAL: create test file in inbox: $!"; close $test; unless (rename $infile, $scratchfile and -f $scratchfile) { + my $err = "$!"; unlink $infile; - abort "FATAL: could not rename file from inbox to scratchpad: $!"; + abort "FATAL: could not rename file from inbox to scratchpad: $err"; } unlink $scratchfile; # test complete } @@ -699,12 +700,14 @@ BEGIN { or abort "FATAL: create test file in staging directory: $!"; close $test; unless (rename $stagefile, $pubfile and -f $pubfile) { + my $err = "$!"; unlink $stagefile; - abort "FATAL: could not rename file from staging to public: $!"; + abort "FATAL: could not rename file from staging to public: $err"; } unless (rename $pubfile, $arcfile and -f $arcfile) { + my $err = "$!"; unlink $pubfile; - abort "FATAL: could not rename file from public to archive: $!"; + abort "FATAL: could not rename file from public to archive: $err"; } unlink $arcfile; # test complete } -- 2.25.1