commit:     30b519f15fce4f78de28ccd49b829c327072f4a6
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Sep 13 01:10:32 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Sat Sep 13 01:12:24 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=30b519f1

Delete interim archives for which installation fails

Presently, the generate_archive() subroutine performs these steps:

1) generates a new locale archive beneath $TEMPDIR
2) installs it with a suffix that incorporates $$ (the PID of perl)
3) calls rename so as to conclude the installation procedure

However, it is possible for an error to occur after the second step has
successfully concluded, yet before the third step has successfully
concluded. In that case, the interim archive will linger.

# ls /usr/lib/locale
locale-archive locale-archive.3241796

Address this issue by replacing the $TEMPDIR scalar variable with the
@TEMPFILES array variable and ensuring that the path of the interim
archive is pushed to it. The elements of the array shall be purged by
the rm(1) utility, as executed by the END block.

Link: https://bugs.gentoo.org/962753#c9
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/locale-gen b/locale-gen
index d2a6a4c..f2a3ac5 100755
--- a/locale-gen
+++ b/locale-gen
@@ -23,7 +23,7 @@ my $VERSION = '3.5';
 
 my $DEFERRED_SIGNAL = '';
 my $PID = $$;
-my $TEMPDIR;
+my @TEMPFILES;
 
 # Unset BASH_ENV for security reasons. Even as sh(1), bash acts upon it.
 delete $ENV{'BASH_ENV'};
@@ -104,7 +104,7 @@ umask 0022;
        check_archive_dir($prefix, $locale_dir);
 
        # Create a temporary directory and switch to it.
-       $TEMPDIR = enter_tempdir($prefix);
+       push @TEMPFILES, enter_tempdir($prefix);
 
        # Compile the selected locales.
        generate_locales($opt{'jobs'}, @locales);
@@ -527,7 +527,7 @@ sub generate_archive ($prefix, $gentoo_prefix, $locale_dir, 
$do_update, @canonic
 
        # Move the newly minted archive into the appropriate filesystem. Use
        # mv(1), since there is a chance of crossing a filesystem boundary.
-       my $interim_path = "$final_path.$$";
+       push @TEMPFILES, my $interim_path = "$final_path.$$";
        run('mv', '--', catfile($output_dir, 'locale-archive'), $interim_path);
 
        # If a prior archive exists, attempt to preserve its SELinux label.
@@ -671,9 +671,9 @@ sub can_run ($bin) {
 
 END {
        if ($$ == $PID) {
-               if (length $TEMPDIR) {
+               if (@TEMPFILES) {
                        local $?;
-                       system 'rm', '-r', '--', $TEMPDIR;
+                       system 'rm', '-rf', '--', @TEMPFILES;
                }
 
                # The default SIGINT and SIGTERM handlers are suppressed by

Reply via email to