Subject: [PATCH] Set non-zero size if there are any files in the package

From: Wolf <[email-masked]>
Date: Fri, 9 Apr 2021 01:14:26 +0200

If there are only empty files in the pkgdir, on some filesystems
(discovered on btrfs), du might return 0 for the sum size of the files.
But apk-tools considers packages with size = 0 to be virtual and skips
extraction of any files contained.

To work around that (until it is resolved in apk-tools 3), settings the
size to 1 when it is zero AND some files are present should work fine.
---
 abuild.in | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/abuild.in b/abuild.in
index ebeb919..5a66866 100644
--- a/abuild.in
+++ b/abuild.in
@@ -1052,6 +1052,13 @@ prepare_metafiles() {
 	esac
 
 	local size=$(du -sk | awk '{print $1 * 1024}')
+	# If package contains only empty files, the size might be 0. But due to
+	# apk-tools 2 considering packages with size = 0 virtual, nothing is
+	# extracted. That will be solved in apk-tools 3. As a workaround we can
+	# set the size to 1 if any files are present.
+	if [ "$size" -eq 0 ] && [ -n "$(find . ! -name .)" ]; then
+		size=1
+	fi
 
 	if [ "$arch" != "$apkbuild_arch" ]; then
 		local msg="Split function set arch=\"$arch\" for $name, use subpackages=pkg:split:arch format instead"
-- 
2.31.0