[lxc-devel] [distrobuilder/master] Fix checksum matching

monstermunchkin on Github lxc-bot at linuxcontainers.org
Wed Apr 15 17:03:39 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 359 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200415/b5b07846/attachment.bin>
-------------- next part --------------
From 26a6b1569276be6439b83924151c5c421b6ff211 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 15 Apr 2020 19:02:15 +0200
Subject: [PATCH 1/2] shared/util: Fix checksum matching

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/util.go | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/shared/util.go b/shared/util.go
index b26f042..3bf6eed 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -372,11 +372,15 @@ func getChecksum(fname string, hashLen int, r io.Reader) string {
 	scanner := bufio.NewScanner(r)
 
 	for scanner.Scan() {
-		if !strings.Contains(scanner.Text(), fname) {
+		fields := strings.Split(scanner.Text(), " ")
+
+		// We need to special case CentOS, as they don't use the common
+		// "<hash> <filename>" syntax.
+		if strings.TrimSpace(fields[len(fields)-1]) != fname && !strings.Contains(scanner.Text(), fmt.Sprintf("(%s)", fname)) {
 			continue
 		}
 
-		for _, s := range strings.Split(scanner.Text(), " ") {
+		for _, s := range fields {
 			m, _ := regexp.MatchString("[[:xdigit:]]+", s)
 			if !m {
 				continue

From d370ef38f7243b0dfa88e24f72e4dc7a7328987d Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 15 Apr 2020 19:02:48 +0200
Subject: [PATCH 2/2] test: Update checksum matching

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/util_test.go | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/shared/util_test.go b/shared/util_test.go
index 994eae3..955a3ab 100644
--- a/shared/util_test.go
+++ b/shared/util_test.go
@@ -227,6 +227,22 @@ func Test_getChecksum(t *testing.T) {
 		args args
 		want string
 	}{
+		{
+			"stage3-ppc64le-20200414T103003Z.tar.xz",
+			args{
+				"stage3-ppc64le-20200414T103003Z.tar.xz",
+				128,
+				bytes.NewBufferString(`# BLAKE2 (b2sum) HASH
+2c5dc7ce04e4d72204a513e4bfa4bd0129e61a060747537ca748538ea8ed6016656f84c35b4cf2049df91a164977d1d0e506e722443fdb48874e9a0b90c00f7a  /var/tmp/catalyst/builds/default/stage3-ppc64le-20200414T103003Z.tar.xz
+# SHA512 HASH
+e4b9cb10146502310cbedf14197afa9e94b75f7d59c1c6977bff23bac529e9114e3fddb155cfcad9119e466a39f0fcd8d75354e5237da79c9289fe76ee77693d  stage3-ppc64le-20200414T103003Z.tar.xz
+# BLAKE2 (b2sum) HASH
+7e1a1985a41b61ac24c4fdefe7a09237161dc7ff20150f3e02c73115b74778f96c45042ced08e38c931ad6e316dfef80ac3a4c956fcd16528819dd506a320726  /var/tmp/catalyst/builds/default/stage3-ppc64le-20200414T103003Z.tar.xz.CONTENTS
+# SHA512 HASH
+1047f97cbb209fb22d372dffe4461722b5eaf936fc73546a8f036dc52a5d20433921d367288b28b3de5154cad1253b40d32233104c2be45732ebfa413bd9b09b  stage3-ppc64le-20200414T103003Z.tar.xz.CONTENTS`),
+			},
+			"e4b9cb10146502310cbedf14197afa9e94b75f7d59c1c6977bff23bac529e9114e3fddb155cfcad9119e466a39f0fcd8d75354e5237da79c9289fe76ee77693d",
+		},
 		{
 			"CentOS-8-x86_64-1905-dvd1.iso",
 			args{


More information about the lxc-devel mailing list