commit: a009d7c7ab382065555d60250752f11ef40c1c1c
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Aug 6 06:34:38 2025 +0000
Commit: Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Wed Aug 6 06:46:10 2025 +0000
URL: https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=a009d7c7
Improve the diagnostic where /usr/share/i18n/locales cannot be entered
Consider a scenario in which locale-gen(8) is unable to switch to the
directory containing the glibc locale definition files.
# locale-gen --prefix /var/empty
sh: 1: cd: can't cd to /var/empty/usr/share/i18n/locales
locale-gen: Failed to compose a list of valid locale names from '/var/e
pty/usr/share/i18n/locales'
In this case, the implementation of sh(1) is provided by dash. I find
its diagnostic message to be lacking because it does not explain why it
cannot switch to the requested directory. That is, it could have
reported the chdir(2) error.
Address this minor issue by having the Perl interpreter attempt to
switch to the directory before executing sh(1) and find(1) and throwing
a tailored exception if it cannot.
# locale-gen --prefix /var/empty
locale-gen: Can't chdir to '/var/empty/usr/share/i18n/locales': No such
file or directory
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
locale-gen | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/locale-gen b/locale-gen
index 25204ca..8ee16e9 100755
--- a/locale-gen
+++ b/locale-gen
@@ -268,13 +268,16 @@ sub read_config ($prefix, @paths) {
}
sub get_valid_locales ($prefix) {
- my $top = local $ENV{'TOP'} = catdir($prefix,
'/usr/share/i18n/locales');
- my @paths = qx{ cd -- "\$TOP" && find . ! -path . -prune ! -path '*\n*'
-type f -exec grep -lxF LC_IDENTIFICATION {} + };
- if ($? != 0 || ! @paths) {
+ my $top = catdir($prefix, '/usr/share/i18n/locales');
+ my $cmd = qq{ find . ! -path . -prune ! -path '*\n*' -type f -exec grep
-lxF LC_IDENTIFICATION {} + };
+ if (! chdir $top) {
+ die "$PROGRAM: Can't chdir to '$top': $!\n";
+ } elsif (! (my @paths = readpipe $cmd) || $? != 0) {
die "$PROGRAM: Failed to compose a list of valid locale names
from '$top'\n";
+ } else {
+ chomp @paths;
+ return map +( (splitpath($_))[-1] ), @paths;
}
- chomp @paths;
- return map +( (splitpath($_))[-1] ), @paths;
}
sub get_valid_charmaps ($prefix) {