Update manifest.Fetch to also parse "tag" from repo strings
This commit is contained in:
parent
e40181b728
commit
8a9af33071
|
|
@ -2,11 +2,12 @@ package manifest
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// "dir" is the default "library directory"
|
||||
|
|
@ -14,19 +15,26 @@ import (
|
|||
// if "repo" is a URL, the remote contents of that URL
|
||||
// the file "repo"
|
||||
// the file "dir/repo"
|
||||
func Fetch(dir, repo string) (string, *Manifest2822, error) {
|
||||
// (repoName, tagName, man, err)
|
||||
func Fetch(dir, repo string) (string, string, *Manifest2822, error) {
|
||||
repoName := path.Base(repo)
|
||||
tagName := ""
|
||||
if tagIndex := strings.IndexRune(repoName, ':'); tagIndex > 0 {
|
||||
tagName = repoName[tagIndex+1:]
|
||||
repoName = repoName[:tagIndex]
|
||||
repo = strings.TrimSuffix(repo, ":"+tagName)
|
||||
}
|
||||
|
||||
u, err := url.Parse(repo)
|
||||
if err == nil && u.IsAbs() {
|
||||
// must be remote URL!
|
||||
resp, err := http.Get(repo)
|
||||
if err != nil {
|
||||
return repoName, nil, err
|
||||
return repoName, tagName, nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
man, err := Parse(resp.Body)
|
||||
return repoName, man, err
|
||||
return repoName, tagName, man, err
|
||||
}
|
||||
|
||||
// try file paths
|
||||
|
|
@ -36,14 +44,14 @@ func Fetch(dir, repo string) (string, *Manifest2822, error) {
|
|||
} {
|
||||
f, err := os.Open(fileName)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return repoName, nil, err
|
||||
return repoName, tagName, nil, err
|
||||
}
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
man, err := Parse(f)
|
||||
return repoName, man, err
|
||||
return repoName, tagName, man, err
|
||||
}
|
||||
}
|
||||
|
||||
return repoName, nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, dir)
|
||||
return repoName, tagName, nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, dir)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue