Adjust the signature of Fetch to include the "repo name"

This commit is contained in:
Tianon Gravi 2016-05-27 11:47:30 -07:00
parent de5435319f
commit f346802da9
1 changed files with 11 additions and 6 deletions

View File

@ -3,11 +3,14 @@ package manifest
import (
"os"
"net/http"
"path"
"path/filepath"
)
// "dir" is the default "library directory"; returns the parsed version of (in order) the file "repo", the file "dir/repo", or the remote file fetched from the URL "repo"
func Fetch(dir, repo string) (*Manifest2822, error) {
func Fetch(dir, repo string) (string, *Manifest2822, error) {
repoName := path.Base(repo)
// try file paths first
for _, fileName := range []string{
repo,
@ -15,21 +18,23 @@ func Fetch(dir, repo string) (*Manifest2822, error) {
} {
f, err := os.Open(fileName)
if err != nil && !os.IsNotExist(err) {
return nil, err
return repoName, nil, err
}
if err == nil {
defer f.Close()
return Parse(f)
man, err := Parse(f)
return repoName, man, err
}
}
// must be remote URL
resp, err := http.Get(repo)
if err != nil {
return nil, err
return repoName, nil, err
}
defer resp.Body.Close()
return Parse(resp.Body)
man, err := Parse(resp.Body)
return repoName, man, err
//return nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, dir)
//return repoName, nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, dir)
}