commit:     02b2ac6ee591e4ee65eb131fa8038dc473678527
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Aug  4 23:10:54 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Mon Aug  4 23:15:09 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=02b2ac6e

Only check the prospective archive dir once there is work to be done

The locale-gen(1) utility combines the values of the 'prefix' and
'locale_dir' variables to form the directory that is expected to contain
the locale archive, then checks whether said directory exists and can be
modified by the effective UID. Presently, this check is performed
immediately after the command line options are validated.

Instead, perform the check at the point that locale generation is about
to commence. Further, move the code responsible for performing the check
into a new subroutine by the name of check_archive_dir.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/locale-gen b/locale-gen
index 18e4fa6..7df6be1 100755
--- a/locale-gen
+++ b/locale-gen
@@ -53,12 +53,6 @@ delete @ENV{'BASH_ENV', 'CDPATH'};
        my %opt = parse_opts($gentoo_prefix, @ARGV);
        my $prefix = $opt{'prefix'} // $gentoo_prefix;
 
-       # A proxy check is justified because compilation may take a long time.
-       my $archive_dir = catdir($prefix, $locale_dir);
-       if (! utime undef, undef, $archive_dir) {
-               die "$PROGRAM: Aborting because UID $> can't modify 
'$archive_dir': $!\n";
-       }
-
        # Honour the --quiet option.
        if ($opt{'quiet'} && ! open *STDOUT, '>/dev/null') {
                die "Can't direct STDOUT to /dev/null: $!";
@@ -109,6 +103,9 @@ delete @ENV{'BASH_ENV', 'CDPATH'};
                exit 0;
        }
 
+       # A proxy check is justified because compilation may take a long time.
+       check_archive_dir($prefix, $locale_dir);
+
        # Create a temporary directory and switch to it.
        enter_tempdir($prefix);
 
@@ -346,6 +343,15 @@ sub parse_entry ($locale, $charmap) {
        return $locale, $charmap, $canonical;
 }
 
+sub check_archive_dir ($prefix, $locale_dir) {
+       my $archive_dir = catdir($prefix, $locale_dir);
+
+       # Check whether the directory exists and can be modified by the EUID.
+       if (! utime undef, undef, $archive_dir) {
+               die "$PROGRAM: Aborting because UID $> can't modify 
'$archive_dir': $!\n";
+       }
+}
+
 sub enter_tempdir ($prefix) {
        # Given that /tmp might be a tmpfs, prefer /var/tmp so as to avoid
        # undue memory pressure.

Reply via email to