Skip to content

Commit 840158d

Browse files
authored
Merge pull request #11 from infosiftr/fix-accidental-additive-default-values
Fix the case of default Architectures being added to any Global Architectures
2 parents 235f7e4 + 6c0c78b commit 840158d

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

manifest/example_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ GitFetch: refs/heads/master
1919
GitRepo: https://github.com/docker-library/golang.git
2020
SharedTags: latest
2121
arm64v8-GitRepo: https://github.com/docker-library/golang.git
22+
Architectures: amd64
2223
2324
2425
# hi

manifest/rfc2822.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,32 @@ type decoderWrapper struct {
401401
}
402402

403403
func (decoder *decoderWrapper) Decode(entry *Manifest2822Entry) error {
404+
// reset Architectures and SharedTags so that they can be either inherited or replaced, not additive
405+
sharedTags := entry.SharedTags
406+
entry.SharedTags = nil
407+
arches := entry.Architectures
408+
entry.Architectures = nil
409+
404410
for {
405411
err := decoder.Decoder.Decode(entry)
406412
if err != nil {
407413
return err
408414
}
415+
409416
// ignore empty paragraphs (blank lines at the start, excess blank lines between paragraphs, excess blank lines at EOF)
410-
if len(entry.Paragraph.Order) > 0 {
411-
return nil
417+
if len(entry.Paragraph.Order) == 0 {
418+
continue
419+
}
420+
421+
// if we had no SharedTags or Architectures, restore our "default" (original) values
422+
if len(entry.SharedTags) == 0 {
423+
entry.SharedTags = sharedTags
424+
}
425+
if len(entry.Architectures) == 0 {
426+
entry.Architectures = arches
412427
}
428+
429+
return nil
413430
}
414431
}
415432

@@ -442,10 +459,6 @@ func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
442459
for {
443460
entry := manifest.Global.Clone()
444461

445-
// reset Architectures and SharedTags so that they can be either inherited or replaced, not additive
446-
entry.SharedTags = nil
447-
entry.Architectures = nil
448-
449462
err := decoder.Decode(&entry)
450463
if err == io.EOF {
451464
break
@@ -454,13 +467,6 @@ func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
454467
return nil, err
455468
}
456469

457-
if len(entry.SharedTags) == 0 {
458-
entry.SharedTags = manifest.Global.SharedTags
459-
}
460-
if len(entry.Architectures) == 0 {
461-
entry.Architectures = manifest.Global.Architectures
462-
}
463-
464470
if !GitFetchRegex.MatchString(entry.GitFetch) {
465471
return nil, fmt.Errorf(`Tags %q has invalid GitFetch (must be "refs/heads/..." or "refs/tags/..."): %q`, entry.TagsString(), entry.GitFetch)
466472
}

0 commit comments

Comments
 (0)