commit:     7eba2ce43d220fd4a2ff471202387b62934b6345
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Aug 10 08:04:38 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Sun Aug 10 08:12:13 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=7eba2ce4

Ensure that get_valid_locales() restores the current working directory

The get_valid_locales() subroutine should not change the current working
directory as a side effect of being called. Though the current working
directory is eventually changed again by calling enter_tempdir(), this
effect is enough to break the use of the -c option with relative paths.

# cd /usr/share/i18n
# locale-gen -c SUPPORTED
locale-gen: Can't open 'SUPPORTED': No such file or directory

Address this regression by ensuring that the prior current working
directory is restored before get_valid_locales() returns.

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

 locale-gen | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/locale-gen b/locale-gen
index 998df2c..d1d66d7 100755
--- a/locale-gen
+++ b/locale-gen
@@ -7,6 +7,7 @@
 
 use v5.36;
 
+use Cwd qw(getcwd);
 use Errno qw(ENOENT);
 use Fcntl qw(SEEK_SET);
 use File::Spec::Functions qw(canonpath catfile catdir splitpath);
@@ -283,12 +284,15 @@ sub read_config ($prefix, @paths) {
 }
 
 sub get_valid_locales ($prefix) {
-       my $top = catdir($prefix, '/usr/share/i18n/locales');
        my $cmd = qq{ find . ! -path . -prune ! -path '*\n*' -type f -exec grep 
-lxF LC_IDENTIFICATION {} + };
+       my $top = catdir($prefix, '/usr/share/i18n/locales');
+       my $pwd = getcwd();
        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";
+       } elsif (defined $pwd && ! chdir $pwd) {
+               die "$PROGRAM: Can't chdir to '$pwd': $!\n";
        } else {
                chomp @paths;
                return map +( (splitpath($_))[-1] ), @paths;

Reply via email to