pgindent: Always clean up .BAK files from pg_bsd_indent

The previous commit let pgindent clean up File::Temp files on SIGINT.
This extends that to also cleaning up the .BAK files, created by
pg_bsd_indent.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://www.postgresql.org/message-id/flat/DFCDD5H4J7VX.3GJKRBBDCKQ86@jeltef.nl
This commit is contained in:
Peter Eisentraut 2026-03-27 14:24:52 +01:00
parent 801de0bd44
commit 6857947db5

View file

@ -28,6 +28,12 @@ use Getopt::Long;
$SIG{INT} = sub { exit 130; }; # 128 + 2 (SIGINT)
$SIG{TERM} = sub { exit 143; }; # 128 + 15 (SIGTERM)
# pg_bsd_indent creates a .BAK file that File::Temp doesn't know about. This
# END block makes sure that that file is cleaned up in case someone presses
# Ctrl+C during pgindent.
my $bak_to_cleanup;
END { unlink $bak_to_cleanup if defined $bak_to_cleanup; }
# Update for pg_bsd_indent version
my $INDENT_VERSION = "2.1.2";
@ -296,11 +302,14 @@ sub run_indent
print $tmp_fh $source;
$tmp_fh->close();
$bak_to_cleanup = "$filename.BAK";
$$error_message = `$cmd $filename 2>&1`;
return "" if ($? || length($$error_message) > 0);
unlink "$filename.BAK";
unlink $bak_to_cleanup;
$bak_to_cleanup = undef;
open(my $src_out, '<', $filename) || die $!;
local ($/) = undef;