[lxc-devel] [distrobuilder/master] sources: Fix latest Arch Linux release

monstermunchkin on Github lxc-bot at linuxcontainers.org
Wed Mar 6 08:32:10 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 489 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190306/58fc0bd9/attachment.bin>
-------------- next part --------------
From 9d545ac5fc3b870a8def2bea8dfd0155b292c42d Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 6 Mar 2019 09:23:12 +0100
Subject: [PATCH] sources: Fix latest Arch Linux release

The `latest/` path is not available on all Arch Linux mirrors.
Therefore, releases are determined by checking all paths.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 sources/archlinux-http.go | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/sources/archlinux-http.go b/sources/archlinux-http.go
index df7cd47..823c9a0 100644
--- a/sources/archlinux-http.go
+++ b/sources/archlinux-http.go
@@ -8,6 +8,8 @@ import (
 	"path"
 	"path/filepath"
 	"regexp"
+	"sort"
+	"strings"
 
 	"github.com/lxc/distrobuilder/shared"
 
@@ -111,29 +113,27 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro
 }
 
 func (s *ArchLinuxHTTP) getLatestRelease(URL string, arch string) (string, error) {
-	u, err := url.Parse(URL)
+	doc, err := htmlquery.LoadURL(URL)
 	if err != nil {
 		return "", err
 	}
 
-	u.Path = path.Join(u.Path, "latest")
+	re := regexp.MustCompile(`^\d{4}\.\d{2}\.\d{2}/?$`)
 
-	doc, err := htmlquery.LoadURL(u.String())
-	if err != nil {
-		return "", err
-	}
+	var releases []string
 
-	node := htmlquery.FindOne(doc, `//a[starts-with(text(),'archlinux-bootstrap-')][ends-with(text(),'.tar.gz')][@href]/text()`)
-	if node == nil {
-		return "", fmt.Errorf("Failed to determine latest release")
+	for _, node := range htmlquery.Find(doc, `//a[@href]/text()`) {
+		if re.MatchString(node.Data) {
+			releases = append(releases, strings.TrimSuffix(node.Data, "/"))
+		}
 	}
 
-	re := regexp.MustCompile(fmt.Sprintf(`^archlinux-bootstrap-(\d{4}\.\d{2}\.\d{2})-%s.tar.gz$`, arch))
-	match := re.FindStringSubmatch(node.Data)
-
-	if len(match) != 2 {
+	if len(releases) == 0 {
 		return "", fmt.Errorf("Failed to determine latest release")
 	}
 
-	return match[1], nil
+	// Sort releases in case they're out-of-order
+	sort.Strings(releases)
+
+	return releases[len(releases)-1], nil
 }


More information about the lxc-devel mailing list