[lxc-devel] [distrobuilder/master] sources: Use fallback openSUSE image if needed
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Tue May 7 10:43:31 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/20190507/c524dca4/attachment.bin>
-------------- next part --------------
From 2dd2a9a84697fec25e8bbdc9b7100a5fa45fcdb5 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 7 May 2019 12:18:30 +0200
Subject: [PATCH] sources: Use fallback openSUSE image if needed
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
sources/opensuse-http.go | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/sources/opensuse-http.go b/sources/opensuse-http.go
index bac65aa..0889ef2 100644
--- a/sources/opensuse-http.go
+++ b/sources/opensuse-http.go
@@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"regexp"
+ "sort"
"strings"
lxd "github.com/lxc/lxd/shared"
@@ -166,14 +167,27 @@ func (s *OpenSUSEHTTP) getTarballName(u *url.URL, release, arch string) string {
nodes := htmlquery.Find(doc, `//a/@href`)
re := regexp.MustCompile(fmt.Sprintf("^opensuse-%s-image.*%s.*\\.tar.xz$", release, arch))
+ var builds []string
+
for _, n := range nodes {
text := htmlquery.InnerText(n)
- if !re.MatchString(text) || strings.Contains(text, "Build") {
+ if !re.MatchString(text) {
continue
}
- return text
+ if strings.Contains(text, "Build") {
+ builds = append(builds, text)
+ } else {
+ return text
+ }
+ }
+
+ if len(builds) > 0 {
+ // Unfortunately, the link to the latest build is missing, hence we need
+ // to manually select the latest build.
+ sort.Strings(builds)
+ return builds[len(builds)-1]
}
return ""
More information about the lxc-devel
mailing list