[lxc-devel] [distrobuilder/master] sources: Fix path to openSUSE tarballs
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Fri Apr 26 14:44:46 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/20190426/4159e19b/attachment.bin>
-------------- next part --------------
From 747547ec7e95cfcb7ac74f2bab0872200e8a7ff4 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 26 Apr 2019 16:40:07 +0200
Subject: [PATCH] sources: Fix path to openSUSE tarballs
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
sources/opensuse-http.go | 41 +++++++++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/sources/opensuse-http.go b/sources/opensuse-http.go
index 18d6993..bac65aa 100644
--- a/sources/opensuse-http.go
+++ b/sources/opensuse-http.go
@@ -10,9 +10,11 @@ import (
"os"
"path"
"path/filepath"
+ "regexp"
"strings"
lxd "github.com/lxc/lxd/shared"
+ "gopkg.in/antchfx/htmlquery.v1"
"github.com/lxc/distrobuilder/shared"
)
@@ -126,8 +128,13 @@ func (s *OpenSUSEHTTP) getPathToTarball(baseURL string, release string, arch str
return ""
}
- u.Path = path.Join(u.Path, fmt.Sprintf("opensuse-tumbleweed-image.%s-1.0.0.tar.xz",
- arch))
+ tarballName := s.getTarballName(u, "tumbleweed", arch)
+
+ if tarballName == "" {
+ return ""
+ }
+
+ u.Path = path.Join(u.Path, tarballName)
} else {
u.Path = path.Join(u.Path, fmt.Sprintf("openSUSE-Leap-%s", release))
@@ -138,8 +145,36 @@ func (s *OpenSUSEHTTP) getPathToTarball(baseURL string, release string, arch str
u.Path = path.Join(u.Path, "containers_ports")
}
- u.Path = path.Join(u.Path, fmt.Sprintf("opensuse-leap-image.%s-lxc.tar.xz", arch))
+ tarballName := s.getTarballName(u, "leap", arch)
+
+ if tarballName == "" {
+ return ""
+ }
+
+ u.Path = path.Join(u.Path, tarballName)
}
return u.String()
}
+
+func (s *OpenSUSEHTTP) getTarballName(u *url.URL, release, arch string) string {
+ doc, err := htmlquery.LoadURL(u.String())
+ if err != nil || doc == nil {
+ return ""
+ }
+
+ nodes := htmlquery.Find(doc, `//a/@href`)
+ re := regexp.MustCompile(fmt.Sprintf("^opensuse-%s-image.*%s.*\\.tar.xz$", release, arch))
+
+ for _, n := range nodes {
+ text := htmlquery.InnerText(n)
+
+ if !re.MatchString(text) || strings.Contains(text, "Build") {
+ continue
+ }
+
+ return text
+ }
+
+ return ""
+}
More information about the lxc-devel
mailing list