]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pgindent: Always clean up .BAK files from pg_bsd_indent
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 27 Mar 2026 13:24:52 +0000 (14:24 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 27 Mar 2026 13:26:43 +0000 (14:26 +0100)
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

src/tools/pgindent/pgindent

index f78a34eb3ced857dd661c3713ac713b79f9f5f63..5f46aa46482f126e538df61173c7f20b13f95395 100755 (executable)
@@ -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;