[lxc-devel] [distrobuilder/master] sources/oracle: Consider boot images only

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Jun 22 08:35:32 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 310 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200622/9bba8ef7/attachment.bin>
-------------- next part --------------
From 3268298f791a0aedec9da918af72ad474a77711d Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 22 Jun 2020 10:35:07 +0200
Subject: [PATCH] sources/oracle: Consider boot images only

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

diff --git a/sources/oraclelinux-http.go b/sources/oraclelinux-http.go
index 21f99a1..6765b5e 100644
--- a/sources/oraclelinux-http.go
+++ b/sources/oraclelinux-http.go
@@ -35,11 +35,29 @@ func (s *OracleLinuxHTTP) Run(definition shared.Definition, rootfsDir string) er
 	fname := fmt.Sprintf("%s-boot.iso", s.architecture)
 	baseURL := fmt.Sprintf("%s/OL%s", definition.Source.URL, definition.Image.Release)
 
-	latestUpdate, err := s.getLatestUpdate(baseURL)
+	updates, err := s.getUpdates(baseURL)
 	if err != nil {
 		return err
 	}
 
+	var latestUpdate string
+
+	// Only consider updates providing a boot image since we're not interested in the
+	// DVD ISO.
+	for i := len(updates) - 1; i > 0; i-- {
+		fullURL := fmt.Sprintf("%s/%s/%s/%s", baseURL, updates[i], s.architecture, fname)
+
+		resp, err := http.Head(fullURL)
+		if err != nil {
+			continue
+		}
+
+		if resp.StatusCode == http.StatusOK {
+			latestUpdate = updates[i]
+			break
+		}
+	}
+
 	fpath, err := shared.DownloadHash(definition.Image, fmt.Sprintf("%s/%s/%s/%s", baseURL, latestUpdate, s.architecture, fname),
 		"", nil)
 	if err != nil {
@@ -248,27 +266,27 @@ EOF
 	return shared.RunCommand("rsync", "-qa", tempRootDir+"/rootfs/", rootfsDir)
 }
 
-func (s *OracleLinuxHTTP) getLatestUpdate(URL string) (string, error) {
+func (s *OracleLinuxHTTP) getUpdates(URL string) ([]string, error) {
 	re := regexp.MustCompile(`^[uU]\d+/$`)
 
 	doc, err := htmlquery.LoadURL(URL)
 	if err != nil {
-		return "", err
+		return nil, err
 	}
 
-	var latestUpdate string
+	var updates []string
 
 	for _, a := range htmlquery.Find(doc, "//a/@href") {
 		if re.MatchString(a.FirstChild.Data) {
-			latestUpdate = a.FirstChild.Data
+			updates = append(updates, strings.TrimSuffix(a.FirstChild.Data, "/"))
 		}
 	}
 
-	if latestUpdate == "" {
-		return "", fmt.Errorf("No update found")
+	if len(updates) == 0 {
+		return nil, fmt.Errorf("No updates found")
 	}
 
-	return strings.TrimSuffix(latestUpdate, "/"), nil
+	return updates, nil
 }
 
 func (s OracleLinuxHTTP) unpackRootfsImage(imageFile string, target string) error {


More information about the lxc-devel mailing list