Skip to content

Commit

Permalink
fix double slash in upstreamURL
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFox0x7 authored Jul 23, 2023
1 parent 63f4d86 commit f221363
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
10 changes: 3 additions & 7 deletions downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *Downloader) download() error {
}

func (d *Downloader) downloadFromUpstream(repoURL string) error {
upstreamURL := repoURL + "/" + d.urlPath
upstreamURL := repoURL + d.urlPath

var req *http.Request
var err error
Expand Down Expand Up @@ -389,15 +389,11 @@ func (f *RequestedFile) getRepo() *Repo {

// key used for downloaders map; each active Downloader is referenced by its key
func (f *RequestedFile) key() string {
return f.repoName + "/" + f.urlPath()
return f.repoName + f.urlPath()
}

func (f *RequestedFile) urlPath() string {
if f.pathAtRepo == "" {
return f.fileName
} else {
return f.pathAtRepo + "/" + f.fileName
}
return f.pathAtRepo + "/" + f.fileName
}

// mkCacheDir creates cache directory if one does not exist
Expand Down
37 changes: 37 additions & 0 deletions downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,40 @@ func TestParallelDownload(t *testing.T) {

counter.Wait()
}

func TestRequestedFile(t *testing.T) {
path := "/repo/noPath/foobar-3.3.6-7-x86_64.pkg.tar.zst"

f, err := parseRequestURL(path)
if err != nil {
t.Error(err)
}
if f.urlPath() != "/foobar-3.3.6-7-x86_64.pkg.tar.zst" {
t.Errorf("expected '%s; got '%s", "/foobar-3.3.6-7-x86_64.pkg.tar.zst", f.urlPath())
}
if f.key() != "noPath/foobar-3.3.6-7-x86_64.pkg.tar.zst" {
t.Errorf("expected '%s; got '%s", "noPath/foobar-3.3.6-7-x86_64.pkg.tar.zst", f.key())
}
path = "/repo/extened/path/bar-222.pkg.tar.zst"
f, err = parseRequestURL(path)
if err != nil {
t.Error(err)
}
if f.urlPath() != "/path/bar-222.pkg.tar.zst" {
t.Errorf("expected '%s; got '%s", "/path/bar-222.pkg.tar.zst", f.urlPath())
}
if f.key() != "extened/path/bar-222.pkg.tar.zst" {
t.Errorf("expected '%s; got '%s", "extened/path/bar-222.pkg.tar.zst", f.key())
}
path = "/repo/upstream/extra/os/x86_64/linux-5.19.pkg.tar.zst"
f, err = parseRequestURL(path)
if err != nil {
t.Error(err)
}
if f.urlPath() != "/extra/os/x86_64/linux-5.19.pkg.tar.zst" {
t.Errorf("expected '%s; got '%s", "/extra/os/x86_64/linux-5.19.pkg.tar.zst", f.urlPath())
}
if f.key() != "upstream/extra/os/x86_64/linux-5.19.pkg.tar.zst" {
t.Errorf("expected '%s; got '%s", "upstream/extra/os/x86_64/linux-5.19.pkg.tar.zst", f.key())
}
}

0 comments on commit f221363

Please sign in to comment.