Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sources/funtoo: Use symlinks #840

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading