From: Peter Eisentraut Date: Fri, 27 Mar 2026 13:24:52 +0000 (+0100) Subject: pgindent: Always clean up .BAK files from pg_bsd_indent X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6857947db5bbec823226cd5234f088524f933caa;p=thirdparty%2Fpostgresql.git 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 Discussion: https://www.postgresql.org/message-id/flat/DFCDD5H4J7VX.3GJKRBBDCKQ86@jeltef.nl --- diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent index f78a34eb3ce..5f46aa46482 100755 --- a/src/tools/pgindent/pgindent +++ b/src/tools/pgindent/pgindent @@ -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;