File 0002-snap-squashfs-fix-minimum-snap-size-on-non-Debian.patch of Package snapd

From 6ac06898707aca3c9375a7ca3656a11ba40937cc Mon Sep 17 00:00:00 2001
Message-ID: <6ac06898707aca3c9375a7ca3656a11ba40937cc.1700482457.git.maciek.borzecki@gmail.com>
From: Maciej Borzecki <maciek.borzecki@gmail.com>
Date: Mon, 20 Nov 2023 13:10:22 +0100
Subject: [PATCH] snap/squashfs: fix minimum snap size on non-Debian

The mksquashfs build on distros such as Arch, openSUSE, will pad the filesystem
image to 64k by default (which is the default behavior). Ideally this should be
fixed by controlling the actual arguments passed to mksquashfs, but this may
have unexpected effects. Instead provide a workaround for said distros.

Signed-off-by: Maciej Borzecki <maciek.borzecki@gmail.com>

Upstream-status: submitted https://github.com/snapcore/snapd/pull/13376
---
 snap/squashfs/squashfs.go      | 3 +++
 snap/squashfs/squashfs_test.go | 9 ++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/snap/squashfs/squashfs.go b/snap/squashfs/squashfs.go
index 9a7a58533c850fdb93a64fa21d8b9426d2793649..8fdc3f4d815b3c8cb13f20572a216e36dc4a80d4 100644
--- a/snap/squashfs/squashfs.go
+++ b/snap/squashfs/squashfs.go
@@ -509,6 +509,8 @@ type BuildOpts struct {
 // partition table from the snap when a loopback device is created from it. If the snap
 // is smaller than this size, some versions of the kernel will print error logs while
 // scanning the loopback device for partitions.
+// TODO: this isn't reliable, on some distros mkfsquashfs pads up to 64k by
+// default
 const MinimumSnapSize int64 = 16384
 
 // Build builds the snap.
@@ -536,6 +538,7 @@ func (s *Snap) Build(sourceDir string, opts *BuildOpts) error {
 	if err != nil {
 		cmd = exec.Command("mksquashfs")
 	}
+	// TODO: consider adding -nopad to control the padding of the fs image
 	cmd.Args = append(cmd.Args,
 		".", fullSnapPath,
 		"-noappend",
diff --git a/snap/squashfs/squashfs_test.go b/snap/squashfs/squashfs_test.go
index cd924d7199a6b55754593676e207cd66bc282696..dafd81a3f613cd2f7616d24250b140fa648087f6 100644
--- a/snap/squashfs/squashfs_test.go
+++ b/snap/squashfs/squashfs_test.go
@@ -981,7 +981,14 @@ func (s *SquashfsTestSuite) TestBuildBelowMinimumSize(c *C) {
 	size, err := sn.Size()
 	c.Assert(err, IsNil)
 
-	c.Assert(size, Equals, squashfs.MinimumSnapSize)
+	switch size {
+	case squashfs.MinimumSnapSize:
+		// all good on Debian based distros
+	case 65536:
+		// this is expected on non-Debian based distros
+	default:
+		c.Fatalf("unexpected squashfs size %v", size)
+	}
 }
 
 func (s *SquashfsTestSuite) TestBuildAboveMinimumSize(c *C) {
-- 
2.42.1

openSUSE Build Service is sponsored by