The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/334

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===

From 63b7a886b031b61880b5bb0bc4ba538c4e1782da Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Wed, 20 May 2020 08:47:03 +0200
Subject: [PATCH] shared/net: Fix checksum check regression

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 shared/net.go | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/shared/net.go b/shared/net.go
index 8ac9081..2c8be8e 100644
--- a/shared/net.go
+++ b/shared/net.go
@@ -21,7 +21,6 @@ func DownloadHash(def DefinitionImage, file, checksum string, 
hashFunc hash.Hash
        var (
                client http.Client
                hashes []string
-               hash   string
                err    error
        )
        targetDir := GetTargetDir(def)
@@ -69,6 +68,8 @@ func DownloadHash(def DefinitionImage, file, checksum string, 
hashFunc hash.Hash
 
                        result := fmt.Sprintf("%x", hashFunc.Sum(nil))
 
+                       var hash string
+
                        for _, h := range hashes {
                                if result == h {
                                        hash = h
@@ -94,15 +95,27 @@ func DownloadHash(def DefinitionImage, file, checksum 
string, hashFunc hash.Hash
                fmt.Printf("%s\r", progress.Text)
        }
 
-       if hashFunc != nil {
-               hashFunc.Reset()
-       }
-       _, err = lxd.DownloadFileHash(&client, "", progress, nil, imagePath, 
file, hash, hashFunc, image)
-       if err != nil {
-               if checksum == "" && strings.HasPrefix(err.Error(), "Hash 
mismatch") {
-                       return targetDir, nil
+       if checksum == "" {
+               _, err = lxd.DownloadFileHash(&client, "", progress, nil, 
imagePath, file, "", nil, image)
+               if err != nil && !strings.HasPrefix(err.Error(), "Hash 
mismatch") {
+                       return "", err
+               }
+       } else {
+               // Check all file hashes in case multiple have been provided.
+               for _, h := range hashes {
+                       if hashFunc != nil {
+                               hashFunc.Reset()
+                       }
+
+                       _, err = lxd.DownloadFileHash(&client, "", progress, 
nil, imagePath, file, h, hashFunc, image)
+                       if err == nil {
+                               break
+                       }
+               }
+
+               if err != nil {
+                       return "", err
                }
-               return "", err
        }
 
        fmt.Println("")
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to