[pacman-dev] [PATCH] makepkg: use --apparent-size when du supports it

Allan McRae allan at archlinux.org
Mon Oct 22 23:41:53 EDT 2012


Amazingly, using "sleep 1" to convince btrfs to report correct file
sizes is only a 90% fix.  Sometimes more sleep is needed.

Instead we use the --apparent-size argument to du to get actual file
sizes. This is used only on Linux as the various BSDs do not support
this argument.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 configure.ac          | 2 ++
 scripts/Makefile.am   | 1 +
 scripts/makepkg.sh.in | 7 +------
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index 03fb015..2323669 100644
--- a/configure.ac
+++ b/configure.ac
@@ -300,11 +300,13 @@ GCC_GNU89_INLINE_CC
 INODECMD="stat -c '%i %n'"
 SIZECMD="stat -c %s"
 SEDINPLACE="sed -i"
+DUFLAGS="-sk --apparent-size"
 case "${host_os}" in
 	*bsd*)
 		INODECMD="stat -f '%i %n'"
 		SIZECMD="stat -f %z"
 		SEDINPLACE="sed -i \"\""
+		DUFLAGS="-sk"
 		;;
 esac
 
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 2bd6411..da7047b 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -58,6 +58,7 @@ edit = sed \
 	-e 's|@SIZECMD[@]|$(SIZECMD)|g' \
 	-e 's|@SEDINPLACE[@]|$(SEDINPLACE)|g' \
 	-e 's|@DUPATH[@]|$(DUPATH)|g' \
+	-e 's|@DUFLAGS[@]|$(DUFLAGS)|g' \
 	-e 's|@SCRIPTNAME[@]|$@|g' \
 	-e 's|@configure_input[@]|Generated from $@.sh.in; do not edit by hand.|g'
 
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 5822843..1e9068b 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1704,12 +1704,7 @@ write_pkginfo() {
 		local packager="Unknown Packager"
 	fi
 
-	# btrfs's delayed allocation causes the stat buffers from the kernel to "lie"
-	# to us momentarily and report 0 blocks allocated (which is how du calculates
-	# size). Sleeping for a second here is about the dirtiest thing possible,
-	# but avoids reporting entirely bogus install sizes.
-	sleep 1
-	local size="$(@DUPATH@ -sk)"
+	local size="$(@DUPATH@ @DUFLAGS@)"
 	size="$(( ${size%%[^0-9]*} * 1024 ))"
 
 	msg2 "$(gettext "Generating %s file...")" ".PKGINFO"
-- 
1.8.0



More information about the pacman-dev mailing list