]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
gendocs: correct the calculation of file sizes.
authorJames Youngman <james@youngman.org>
Fri, 17 Jul 2026 11:55:29 +0000 (12:55 +0100)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 17 Jul 2026 17:50:44 +0000 (10:50 -0700)
* build-aux/gendocs.sh (calcsize): do not assume "ls -sk" tells us the
size of the file in KiB.  Calculate it from the file length instead.

build-aux/gendocs.sh

index 80b0a17368669b4f81b9e85e739fd94a19d44255..2b3373ecf7da5ccdb1a2c376cd21a6bfdef7abe5 100755 (executable)
@@ -2,7 +2,7 @@
 # gendocs.sh -- generate a GNU manual in many formats.  This script is
 #   mentioned in maintain.texi.  See the help message below for usage details.
 
-scriptversion=2026-01-01.00
+scriptversion=2026-07-17.13
 
 # Copyright 2003-2026 Free Software Foundation, Inc.
 #
@@ -230,10 +230,24 @@ if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
 fi
 
 # Function to return size of $1 in something resembling kilobytes.
+# We don't use `ls -s` because that can be longer or shorter than
+# the real length of the data (because the file system compresses
+# the file, for example).  We don't use `du -k --apparent-size`
+# because we do not want to assume `du` supports that option.
+#
+# Here's an example of different `ls -s` results on different file
+# systems:
+#
+# $ cp /var/tmp/findutils-manual/find.html find.html
+# $ ls -lsh /var/tmp/findutils-manual/find.html find.html
+# 221K -rw-rw-r-- 1 james james 582K Jul 17 13:01 find.html
+# 584K -rw-rw-r-- 1 james james 582K Jul 17 12:54 /var/tmp/findutils-manual/find.html
 calcsize()
 {
-  set `ls -ks "$1"`
-  echo $1
+  # Determine size in bytes
+  set `env LC_ALL=C wc -c < "$1"`
+  # Emit the size in KiB, rounding up.
+  expr '(' "$1" + 1023 ')' / 1024
 }
 
 # copy_images OUTDIR HTML-FILE...