commit: d01f4edd83cf9d41abe9941244a949a6f1100187
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Aug 11 16:01:25 2025 +0000
Commit: Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Mon Aug 11 16:01:25 2025 +0000
URL: https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=d01f4edd
Report the size of the installed archive
Upon success, have the final diagnostic message report the size of the
installed archive. Further, have it accurately report how many locales
are incorporated by the archive for the -u option.
# printf '%s UTF-8\n' en_US en_GB | locale-gen -c - | tail -n2
Adding 3 locales to the locale archive ...
Successfully installed an archive containing 3 locales, of 2.93 MiB in size.
# printf '%s UTF-8\n' en_AU | locale-gen -u -c - | tail -n2
Adding 1 locale to the locale archive ...
Successfully installed an archive containing 4 locales, of 2.94 MiB in size.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
locale-gen | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/locale-gen b/locale-gen
index 3a1dadf..1513384 100755
--- a/locale-gen
+++ b/locale-gen
@@ -117,10 +117,11 @@ umask 0022;
generate_locales($opt{'jobs'}, @locales);
# Integrate the newly compiled locales into the system's locale archive.
- generate_archive($prefix, $gentoo_prefix, $locale_dir, $opt{'update'},
map +( $_->[2] ), @locales);
+ my $size = generate_archive($prefix, $gentoo_prefix, $locale_dir,
$opt{'update'}, map +( $_->[2] ), @locales);
- my $total = scalar @locales;
- printf "Successfully installed %d locale%s.\n", $total, plural($total);
+ my $total += scalar @locales + scalar %installed_by;
+ printf "Successfully installed an archive containing %d locale%s, of %s
MiB in size.\n",
+ $total, plural($total), round($size / 2 ** 20);
}
sub get_locale_dir () {
@@ -523,6 +524,13 @@ sub generate_archive ($prefix, $gentoo_prefix,
$locale_dir, $do_update, @canonic
}
die "$PROGRAM: Can't rename '$interim_path' to '$final_path':
$!\n";
}
+
+ # Return the size of the archive, in bytes.
+ if (! (my @stat = stat $final_path)) {
+ die "$PROGRAM: Can't stat '$final_path': $!\n";
+ } else {
+ return $stat[7];
+ }
}
sub run_localedef ($prefix, @args) {
@@ -607,6 +615,11 @@ sub get_username () {
return getpwuid($>) // $ENV{'LOGNAME'};
}
+sub round ($number) {
+ # Evaluation conveniently trims insignificant trailing zeroes.
+ return eval(sprintf '%.2f', $number);
+}
+
END {
if ($$ == $PID) {
if (length $TEMPDIR) {