Skip to content

Commit

Permalink
Merge pull request #840 from stgraber/main
Browse files Browse the repository at this point in the history
sources/funtoo: Use symlinks
  • Loading branch information
monstermunchkin authored Apr 30, 2024
2 parents 2eb1040 + 9a10fde commit c563c56
Showing 1 changed file with 3 additions and 69 deletions.
72 changes: 3 additions & 69 deletions sources/funtoo-http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ package sources
import (
"errors"
"fmt"
"net/http"
"net/url"
"path/filepath"
"regexp"
"sort"
"strings"

"gopkg.in/antchfx/htmlquery.v1"

"github.com/lxc/distrobuilder/shared"
)
Expand Down Expand Up @@ -42,43 +36,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 +86,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 c563c56

Please sign in to comment.