Skip to content

Commit 7e50189

Browse files
committed
Use pointers more consistently, allow "fetch" tag validation to check SharedTags too
1 parent 78186ac commit 7e50189

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

manifest/fetch.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
"strings"
1010
)
1111

12+
func validateTagName(man *Manifest2822, repoName, tagName string) error {
13+
if tagName != "" && (man.GetTag(tagName) == nil && len(man.GetSharedTag(tagName)) == 0) {
14+
return fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
15+
}
16+
return nil
17+
}
18+
1219
// "library" is the default "library directory"
1320
// returns the parsed version of (in order):
1421
// if "repo" is a URL, the remote contents of that URL
@@ -33,10 +40,10 @@ func Fetch(library, repo string) (string, string, *Manifest2822, error) {
3340
}
3441
defer resp.Body.Close()
3542
man, err := Parse(resp.Body)
36-
if tagName != "" && man.GetTag(tagName) == nil {
37-
return repoName, tagName, man, fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
43+
if err != nil {
44+
return repoName, tagName, man, err
3845
}
39-
return repoName, tagName, man, err
46+
return repoName, tagName, man, validateTagName(man, repoName, tagName)
4047
}
4148

4249
// try file paths
@@ -55,10 +62,10 @@ func Fetch(library, repo string) (string, string, *Manifest2822, error) {
5562
if err == nil {
5663
defer f.Close()
5764
man, err := Parse(f)
58-
if tagName != "" && man.GetTag(tagName) == nil {
59-
return repoName, tagName, man, fmt.Errorf("tag not found in manifest for %q: %q", repoName, tagName)
65+
if err != nil {
66+
return repoName, tagName, man, err
6067
}
61-
return repoName, tagName, man, err
68+
return repoName, tagName, man, validateTagName(man, repoName, tagName)
6269
}
6370
}
6471

manifest/rfc2822.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,20 @@ func (entry Manifest2822Entry) HasArchitecture(arch string) bool {
308308
}
309309

310310
func (manifest Manifest2822) GetTag(tag string) *Manifest2822Entry {
311-
for _, entry := range manifest.Entries {
311+
for i, entry := range manifest.Entries {
312312
if entry.HasTag(tag) {
313-
return &entry
313+
return &manifest.Entries[i]
314314
}
315315
}
316316
return nil
317317
}
318318

319319
// GetSharedTag returns a list of entries with the given tag in entry.SharedTags (or the empty list if there are no entries with the given tag).
320-
func (manifest Manifest2822) GetSharedTag(tag string) []Manifest2822Entry {
321-
ret := []Manifest2822Entry{}
322-
for _, entry := range manifest.Entries {
320+
func (manifest Manifest2822) GetSharedTag(tag string) []*Manifest2822Entry {
321+
ret := []*Manifest2822Entry{}
322+
for i, entry := range manifest.Entries {
323323
if entry.HasSharedTag(tag) {
324-
ret = append(ret, entry)
324+
ret = append(ret, &manifest.Entries[i])
325325
}
326326
}
327327
return ret

0 commit comments

Comments
 (0)