File 0001-snap-pack-fix-pack-with-integrity-unit-test-on-non-U.patch of Package snapd

From ac4b9a5c10508241ade78a4ce62e3562e2f1d16c Mon Sep 17 00:00:00 2001
Message-ID: <ac4b9a5c10508241ade78a4ce62e3562e2f1d16c.1700481907.git.maciek.borzecki@gmail.com>
From: Maciej Borzecki <maciek.borzecki@gmail.com>
Date: Mon, 20 Nov 2023 12:46:50 +0100
Subject: [PATCH] snap/pack: fix pack with integrity unit test on non-Ubuntu

Apparently on non-Debian/non-Ubuntu systems, the squashfs image file is padded
to 64k by default. Snap does not pass -nopad to squashfs, hence the created
image is in line with however squuashfs was set up on the host.

This fixes the unit test failure on openSUSE blocking the package update since
2.60.

Signed-off-by: Maciej Borzecki <maciek.borzecki@gmail.com>
---
 snap/pack/pack_test.go | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/snap/pack/pack_test.go b/snap/pack/pack_test.go
index bd190bcb9d87a79f96ab2f9456f69846970c802e..fa05aa611e10ae4fc4fcd8b9a15bb1156c419f76 100644
--- a/snap/pack/pack_test.go
+++ b/snap/pack/pack_test.go
@@ -588,15 +588,25 @@ esac
 	c.Assert(err, IsNil)
 	defer snapFile.Close()
 
+	fi, err := snapFile.Stat()
+	c.Assert(err, IsNil)
+
+	integrityStartOffset := squashfs.MinimumSnapSize
+	if fi.Size() > int64(65536) {
+		// on non-Debian, the squashfs image is padded up to 64k,
+		// including the integrator data, the overall size is > 64k
+		integrityStartOffset = 65536
+	}
+
 	// example snap has a size of 16384 (4 blocks)
-	_, err = snapFile.Seek(squashfs.MinimumSnapSize, io.SeekStart)
+	_, err = snapFile.Seek(integrityStartOffset, io.SeekStart)
 	c.Assert(err, IsNil)
 
 	integrityHdr := make([]byte, integrity.HeaderSize)
 	_, err = snapFile.Read(integrityHdr)
 	c.Assert(err, IsNil)
 
-	c.Check(bytes.HasPrefix(integrityHdr, magic), Equals, true)
+	c.Assert(bytes.HasPrefix(integrityHdr, magic), Equals, true)
 
 	var hdr interface{}
 	integrityHdr = bytes.Trim(integrityHdr, "\x00")
@@ -611,7 +621,7 @@ esac
 	c.Assert(err, IsNil)
 	c.Check(hdrSize, Equals, uint64(integrity.HeaderSize+verityHashSize))
 
-	fi, err := snapFile.Stat()
+	fi, err = snapFile.Stat()
 	c.Assert(err, IsNil)
-	c.Check(fi.Size(), Equals, int64(squashfs.MinimumSnapSize+(integrity.HeaderSize+verityHashSize)))
+	c.Check(fi.Size(), Equals, int64(integrityStartOffset+(integrity.HeaderSize+verityHashSize)))
 }
-- 
2.42.1

openSUSE Build Service is sponsored by