commit:     a6c081557721a094bdc549a4b720ab291b7c75fe
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Aug 13 09:23:10 2025 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Wed Aug 13 09:35:27 2025 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=a6c08155

Don't call parse_config() from a try block in read_config()

Presently, the read_config() subroutine employs a try block to catch
exceptions thrown in the case that a given config file cannot be opened.
However, it also calls the parse_config() subroutine from that same
block. Given that config parsing exceptions need not be caught - even if
only to be re-thrown - there is no sense in doing so. Hoist the call so
that it is no longer enclosed by the try block.

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

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

diff --git a/locale-gen b/locale-gen
index 4b5edd6..aa14728 100755
--- a/locale-gen
+++ b/locale-gen
@@ -271,20 +271,21 @@ sub read_config ($prefix, @paths) {
        # valid locale declarations that can be found among them, if any.
        for my $i (keys @paths) {
                my $path = $paths[$i];
+               my $fh;
                try {
-                       my $fh = fopen($path);
-                       $! = 0;
-                       if (my @locales = parse_config($fh, $path, \%locale_by, 
\%charmap_by)) {
-                               return @locales;
-                       }
+                       $fh = fopen($path);
                } catch ($e) {
-                       # Disregard open errors concerning non-existent files
-                       # unless there are no more paths to be tried. Validation
-                       # errors shall also be propagated here.
-                       if ($! != ENOENT || $i == $#paths) {
+                       # Disregard open(2) errors concerning non-existent files
+                       # unless there are no more paths to be tried.
+                       if ($! == ENOENT && $i < $#paths) {
+                               next;
+                       } else {
                                die $e;
                        }
                }
+               if (my @locales = parse_config($fh, $path, \%locale_by, 
\%charmap_by)) {
+                       return @locales;
+               }
        }
 
        # For no locales to have been discovered at this point is exceptional.

Reply via email to