Skip to content

Commit

Permalink
sources/funtoo: Use symlinks
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Apr 30, 2024
1 parent 2eb1040 commit f351600
Showing 1 changed file with 3 additions and 64 deletions.
67 changes: 3 additions & 64 deletions sources/funtoo-http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sources
import (
"errors"
"fmt"
"net/http"
"net/url"
"path/filepath"
"regexp"

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.21.x, ubuntu-20.04)

"regexp" imported and not used

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.21.x, ubuntu-20.04)

"regexp" imported and not used

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.21.x, ubuntu-22.04)

"regexp" imported and not used

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.21.x, ubuntu-22.04)

"regexp" imported and not used

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.22.x, ubuntu-20.04)

"regexp" imported and not used

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.22.x, ubuntu-20.04)

"regexp" imported and not used

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.22.x, ubuntu-22.04)

"regexp" imported and not used

Check failure on line 8 in sources/funtoo-http.go

View workflow job for this annotation

GitHub Actions / Code tests (1.22.x, ubuntu-22.04)

"regexp" imported and not used
Expand Down Expand Up @@ -42,43 +41,9 @@ func (s *funtoo) Run() error {
s.definition.Source.URL, s.definition.Image.Release,
topLevelArch, s.definition.Image.ArchitectureMapped)

releaseDates, err := s.getReleaseDates(baseURL)
if err != nil {
return fmt.Errorf("Failed to get release dates: %w", err)
}

var fname string
var tarball string

// Find a valid release tarball
for i := len(releaseDates) - 1; i >= 0; i-- {
fname = fmt.Sprintf("stage3-%s-%s-%s.tar.xz",
s.definition.Image.ArchitectureMapped, s.definition.Image.Release, releaseDates[i])
tarball = fmt.Sprintf("%s/%s/%s", baseURL, releaseDates[i], fname)

var (
resp *http.Response
err error
)

err = shared.Retry(func() error {
resp, err = http.Head(tarball)
if err != nil {
return fmt.Errorf("Failed to call HEAD on %q: %w", tarball, err)
}

return nil
}, 3)
if err != nil {
return err
}

if resp.StatusCode == http.StatusNotFound {
continue
}

break
}
// Get the latest release tarball.
fname := "stage3-latest.tar.xz"
tarball := fmt.Sprintf("%s/%s", baseURL, fname)

url, err := url.Parse(tarball)
if err != nil {
Expand Down Expand Up @@ -126,29 +91,3 @@ func (s *funtoo) Run() error {

return nil
}

func (s *funtoo) getReleaseDates(URL string) ([]string, error) {
doc, err := htmlquery.LoadURL(URL)
if err != nil {
return nil, fmt.Errorf("Failed to load URL %q: %w", URL, err)
}

re := regexp.MustCompile(`^\d{4}\-\d{2}\-\d{2}/?$`)

var dirs []string

for _, node := range htmlquery.Find(doc, `//a[@href]/text()`) {
if re.MatchString(node.Data) {
dirs = append(dirs, strings.TrimSuffix(node.Data, "/"))
}
}

if len(dirs) == 0 {
return nil, errors.New("Failed to get release dates")
}

// Sort dirs in case they're out-of-order
sort.Strings(dirs)

return dirs, nil
}

0 comments on commit f351600

Please sign in to comment.