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

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) ===
Fixes #144 

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From adb301bf3cb51e258f68ce9a15f4e226d2dbe5a9 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Mon, 4 Mar 2019 13:44:43 +0100
Subject: [PATCH] sources: Get latest release from mirror

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 sources/archlinux-http.go | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/sources/archlinux-http.go b/sources/archlinux-http.go
index dd0b51c..df7cd47 100644
--- a/sources/archlinux-http.go
+++ b/sources/archlinux-http.go
@@ -7,7 +7,7 @@ import (
        "os"
        "path"
        "path/filepath"
-       "strings"
+       "regexp"
 
        "github.com/lxc/distrobuilder/shared"
 
@@ -33,7 +33,7 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, 
rootfsDir string) erro
                var err error
 
                // Get latest release
-               release, err = s.getLatestRelease()
+               release, err = s.getLatestRelease(definition.Source.URL, 
definition.Image.ArchitectureMapped)
                if err != nil {
                        return err
                }
@@ -110,16 +110,30 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, 
rootfsDir string) erro
                definition.Image.ArchitectureMapped))
 }
 
-func (s *ArchLinuxHTTP) getLatestRelease() (string, error) {
-       doc, err := htmlquery.LoadURL("https://www.archlinux.org/download/";)
+func (s *ArchLinuxHTTP) getLatestRelease(URL string, arch string) (string, 
error) {
+       u, err := url.Parse(URL)
        if err != nil {
                return "", err
        }
 
-       node := htmlquery.FindOne(doc, 
`//*[@id="arch-downloads"]/ul[1]/li[1]/text()`)
+       u.Path = path.Join(u.Path, "latest")
+
+       doc, err := htmlquery.LoadURL(u.String())
+       if err != nil {
+               return "", err
+       }
+
+       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")
        }
 
-       return strings.TrimSpace(node.Data), nil
+       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 {
+               return "", fmt.Errorf("Failed to determine latest release")
+       }
+
+       return match[1], nil
 }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to