Skip to content

Commit

Permalink
Fix incorrect handling of packages with packagebase
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Mar 21, 2024
1 parent b91cd47 commit 2ea2bb8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
21 changes: 20 additions & 1 deletion pacman/aur/aur.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,26 @@ func (p *Package) PkgMakeDepends() []string { return p.MakeDepends }

// DownloadURL returns the URL for downloading the PKGBUILD tarball.
func (p *Package) DownloadURL() string {
return fmt.Sprintf("https://aur.archlinux.org%s", p.URLPath)
urlPath := p.URLPath
if p.PackageBase != p.Name {
urlPath = p.downloadURLWithName(p.PackageBase)
}
return fmt.Sprintf("https://aur.archlinux.org%s", urlPath)
}

func (p *Package) downloadURLWithName(baseName string) string {
fromIdx := strings.LastIndex(p.URLPath, "/")
if fromIdx == -1 {
panic(fmt.Sprintf("expect package URLPath to contain '/', got %q", p.URLPath))
}

filename := p.URLPath[fromIdx+1:]
toIdx := strings.Index(filename, ".")
if toIdx == -1 {
panic(fmt.Sprintf("expect package URLPath to contain '.' in package name, got %q", p.URLPath))
}

return p.URLPath[:fromIdx+1] + baseName + filename[toIdx:]
}

const (
Expand Down
11 changes: 11 additions & 0 deletions pacman/aur/aur_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,14 @@ func TestDownloadURL(z *testing.T) {
z.Errorf("download url incorrect: %s", i.DownloadURL())
}
}

func TestDownloadURLWithBaseName(z *testing.T) {
i, err := Read("transgui-qt")
if err != nil {
z.Errorf("unexpected error: %s", err)
z.FailNow()
}
if i.DownloadURL() != "https://aur.archlinux.org/cgit/aur.git/snapshot/transgui.tar.gz" {
z.Errorf("download url incorrect: %s", i.DownloadURL())
}
}
15 changes: 13 additions & 2 deletions repo/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func Download(destdir string, extract bool, clobber bool, pkgnames []string) err
// DownloadPackages downloads the given AUR packages, printing messages for each one.
func DownloadPackages(pkgs aur.Packages, destdir string, extract bool, clobber bool) error {
for _, p := range pkgs {
term.Printf("Downloading: %s\n", p.Name)
pkgname := p.Name
if p.PackageBase != "" {
pkgname = p.PackageBase
}
term.Printf("Downloading: %s\n", pkgname)
download := DownloadTarballAUR
if extract {
download = DownloadExtractAUR
Expand Down Expand Up @@ -90,6 +94,7 @@ func DownloadExtractAUR(ap *aur.Package, destdir string, clobber bool) error {
}
}

term.Debugf("Fetching URL: %s\n", ap.DownloadURL())
response, err := http.Get(ap.DownloadURL())
if err != nil {
return err
Expand All @@ -115,7 +120,11 @@ func DownloadTarballAUR(ap *aur.Package, destdir string, clobber bool) error {
}

url := ap.DownloadURL()
of := ap.Name + ".tar.gz"
filename := ap.Name
if ap.PackageBase != "" {
filename = ap.PackageBase
}
of := filename + ".tar.gz"

// Make sure we don't clobber anything.
if !clobber {
Expand All @@ -124,10 +133,12 @@ func DownloadTarballAUR(ap *aur.Package, destdir string, clobber bool) error {
return err
}
if ex {
term.Debugf("Skipping download: package file already exists: %s\n", of)
return ErrPkgFileExists
}
}

term.Debugf("Fetching URL: %s\n", url)
response, err := http.Get(url)
if err != nil {
return err
Expand Down

0 comments on commit 2ea2bb8

Please sign in to comment.