diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index c0845f23..8b6006f6 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "maps" "net/http" neturl "net/url" "os" @@ -213,13 +214,16 @@ func (r *Remote) Fetch(path string, cacheDirOpt ...string) (string, error) { return "", fmt.Errorf("[bug] cacheDirOpt's length: want 0 or 1, got %d", len(cacheDirOpt)) } - query := u.RawQuery + query, _ := neturl.ParseQuery(u.RawQuery) + + should_cache := query.Get("cache") != "false" + delete(query, "cache") var cacheKey string replacer := strings.NewReplacer(":", "", "//", "_", "/", "_", ".", "_") dirKey := replacer.Replace(srcDir) if len(query) > 0 { - q, _ := neturl.ParseQuery(query) + q := maps.Clone(query) if q.Has("sshkey") { q.Set("sshkey", "redacted") } @@ -262,7 +266,7 @@ func (r *Remote) Fetch(path string, cacheDirOpt ...string) (string, error) { } } - if !cached { + if !cached || !should_cache { var getterSrc string if u.User != "" { getterSrc = fmt.Sprintf("%s://%s@%s%s", u.Scheme, u.User, u.Host, u.Dir) @@ -271,7 +275,7 @@ func (r *Remote) Fetch(path string, cacheDirOpt ...string) (string, error) { } if len(query) > 0 { - getterSrc = strings.Join([]string{getterSrc, query}, "?") + getterSrc = strings.Join([]string{getterSrc, query.Encode()}, "?") } r.Logger.Debugf("remote> downloading %s to %s", getterSrc, getterDst)