[lxc-devel] [distrobuilder/master] sources: Fix sabayon mirror issue

monstermunchkin on Github lxc-bot at linuxcontainers.org
Tue Apr 16 14:05:51 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190416/b7dea269/attachment.bin>
-------------- next part --------------
From ebbe2ed2ddf5dbf8073e7c12b86834c8280239bb Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 16 Apr 2019 16:03:44 +0200
Subject: [PATCH] sources: Fix sabayon mirror issue

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 sources/sabayon.go | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/sources/sabayon.go b/sources/sabayon.go
index 3e280eb..5393163 100644
--- a/sources/sabayon.go
+++ b/sources/sabayon.go
@@ -3,7 +3,9 @@ package sources
 import (
 	"crypto/md5"
 	"fmt"
+	"net/http"
 	"net/url"
+	"path"
 	"path/filepath"
 
 	lxd "github.com/lxc/lxd/shared"
@@ -21,10 +23,20 @@ func NewSabayonHTTP() *SabayonHTTP {
 
 // Run downloads a Sabayon tarball.
 func (s *SabayonHTTP) Run(definition shared.Definition, rootfsDir string) error {
+	var baseURL string
+
 	fname := fmt.Sprintf("Sabayon_Linux_DAILY_%s_tarball.tar.gz",
 		definition.Image.ArchitectureMapped)
-	tarball := fmt.Sprintf("%s/%s", definition.Source.URL, fname)
-	_, err := url.Parse(tarball)
+	tarballPath := fmt.Sprintf("%s/%s", definition.Source.URL, fname)
+
+	resp, err := http.Head(tarballPath)
+	if err != nil {
+		return fmt.Errorf("Couldn't resolve URL: %v", err)
+	}
+
+	baseURL, fname = path.Split(resp.Request.URL.String())
+
+	url, err := url.Parse(fmt.Sprintf("%s/%s", baseURL, fname))
 	if err != nil {
 		return err
 	}
@@ -33,9 +45,9 @@ func (s *SabayonHTTP) Run(definition shared.Definition, rootfsDir string) error
 
 	// From sabayon currently we have only MD5 checksum for now.
 	if definition.Source.SkipVerification {
-		fpath, err = shared.DownloadHash(definition.Image, tarball, "", nil)
+		fpath, err = shared.DownloadHash(definition.Image, url.String(), "", nil)
 	} else {
-		fpath, err = shared.DownloadHash(definition.Image, tarball, tarball+".md5", md5.New())
+		fpath, err = shared.DownloadHash(definition.Image, url.String(), url.String()+".md5", md5.New())
 	}
 	if err != nil {
 		return err


More information about the lxc-devel mailing list