Skip to content

Commit 418ea0d

Browse files
committed
fix: empty priority is no longer valid
1 parent 4962b27 commit 418ea0d

2 files changed

Lines changed: 70 additions & 6 deletions

File tree

‎internal/setup/setup.go‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ type yamlArchive struct {
398398
Version string `yaml:"version"`
399399
Suites []string `yaml:"suites"`
400400
Components []string `yaml:"components"`
401-
Priority int `yaml:"priority"`
401+
Priority *int `yaml:"priority"`
402402
Default bool `yaml:"default"`
403403
PubKeys []string `yaml:"public-keys"`
404404
}
@@ -542,6 +542,7 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) {
542542
// not being used, we will revert back to the default archive behaviour.
543543
hasPriority := false
544544
var defaultArchive string
545+
var archiveNoPriority string
545546
for archiveName, details := range yamlVar.Archives {
546547
if details.Version == "" {
547548
return nil, fmt.Errorf("%s: archive %q missing version field", fileName, archiveName)
@@ -572,18 +573,28 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) {
572573
}
573574
archiveKeys = append(archiveKeys, key)
574575
}
575-
if details.Priority > MaxArchivePriority || details.Priority < MinArchivePriority {
576-
return nil, fmt.Errorf("%s: archive %q has invalid priority value of %d", fileName, archiveName, details.Priority)
577-
}
578-
if details.Priority != 0 {
576+
priority := 0
577+
if details.Priority != nil {
579578
hasPriority = true
579+
if archiveNoPriority != "" {
580+
return nil, fmt.Errorf("%s: archive %q missing priority", fileName, archiveNoPriority)
581+
}
582+
priority = *details.Priority
583+
if priority > MaxArchivePriority || priority < MinArchivePriority {
584+
return nil, fmt.Errorf("%s: archive %q has invalid priority value of %d", fileName, archiveName, priority)
585+
}
586+
} else {
587+
if hasPriority {
588+
return nil, fmt.Errorf("%s: archive %q missing priority", fileName, archiveName)
589+
}
590+
archiveNoPriority = archiveName
580591
}
581592
release.Archives[archiveName] = &Archive{
582593
Name: archiveName,
583594
Version: details.Version,
584595
Suites: details.Suites,
585596
Components: details.Components,
586-
Priority: details.Priority,
597+
Priority: priority,
587598
PubKeys: archiveKeys,
588599
}
589600
}

‎internal/setup/setup_test.go‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,59 @@ var setupTests = []setupTest{{
798798
},
799799
},
800800
},
801+
}, {
802+
summary: "Multiple archives inconsistent use of priorities",
803+
input: map[string]string{
804+
"chisel.yaml": `
805+
format: v1
806+
archives:
807+
foo:
808+
version: 22.04
809+
components: [main, universe]
810+
suites: [jammy]
811+
priority: 20
812+
public-keys: [test-key]
813+
bar:
814+
version: 22.04
815+
components: [universe]
816+
suites: [jammy-updates]
817+
public-keys: [test-key]
818+
public-keys:
819+
test-key:
820+
id: ` + testKey.ID + `
821+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
822+
`,
823+
"slices/mydir/mypkg.yaml": `
824+
package: mypkg
825+
`,
826+
},
827+
relerror: `chisel.yaml: archive "bar" missing priority`,
828+
}, {
829+
summary: "Multiple archives with no priorities",
830+
input: map[string]string{
831+
"chisel.yaml": `
832+
format: v1
833+
archives:
834+
foo:
835+
version: 22.04
836+
components: [main, universe]
837+
suites: [jammy]
838+
public-keys: [test-key]
839+
bar:
840+
version: 22.04
841+
components: [universe]
842+
suites: [jammy-updates]
843+
public-keys: [test-key]
844+
public-keys:
845+
test-key:
846+
id: ` + testKey.ID + `
847+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
848+
`,
849+
"slices/mydir/mypkg.yaml": `
850+
package: mypkg
851+
`,
852+
},
853+
relerror: `chisel.yaml: archives "bar" and "foo" have the same priority value of 0`,
801854
}, {
802855
summary: "Archive with suites unset",
803856
input: map[string]string{

0 commit comments

Comments
 (0)