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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// "dir" is the default "library directory"
|
// "dir" is the default "library directory"
|
||||||
|
|
@ -14,19 +15,26 @@ import (
|
||||||
// if "repo" is a URL, the remote contents of that URL
|
// if "repo" is a URL, the remote contents of that URL
|
||||||
// the file "repo"
|
// the file "repo"
|
||||||
// the file "dir/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)
|
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)
|
u, err := url.Parse(repo)
|
||||||
if err == nil && u.IsAbs() {
|
if err == nil && u.IsAbs() {
|
||||||
// must be remote URL!
|
// must be remote URL!
|
||||||
resp, err := http.Get(repo)
|
resp, err := http.Get(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repoName, nil, err
|
return repoName, tagName, nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
man, err := Parse(resp.Body)
|
man, err := Parse(resp.Body)
|
||||||
return repoName, man, err
|
return repoName, tagName, man, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// try file paths
|
// try file paths
|
||||||
|
|
@ -36,14 +44,14 @@ func Fetch(dir, repo string) (string, *Manifest2822, error) {
|
||||||
} {
|
} {
|
||||||
f, err := os.Open(fileName)
|
f, err := os.Open(fileName)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return repoName, nil, err
|
return repoName, tagName, nil, err
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
man, err := Parse(f)
|
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