diff --git a/internal/archive/archive.go b/internal/archive/archive.go index 0c73ee2a..bd5f23c6 100644 --- a/internal/archive/archive.go +++ b/internal/archive/archive.go @@ -34,7 +34,7 @@ type Options struct { Suites []string Components []string CacheDir string - Priority int + Priority int32 } func Open(options *Options) (Archive, error) { diff --git a/internal/setup/setup.go b/internal/setup/setup.go index 6bc3c2cc..ac2230ee 100644 --- a/internal/setup/setup.go +++ b/internal/setup/setup.go @@ -29,7 +29,7 @@ type Archive struct { Version string Suites []string Components []string - Priority int + Priority int32 } // Package holds a collection of slices that represent parts of themselves. @@ -322,7 +322,7 @@ type yamlArchive struct { Version string `yaml:"version"` Suites []string `yaml:"suites"` Components []string `yaml:"components"` - Priority int `yaml:"priority"` + Priority int32 `yaml:"priority"` } type yamlPackage struct { diff --git a/internal/setup/setup_test.go b/internal/setup/setup_test.go index 10b39269..976a1846 100644 --- a/internal/setup/setup_test.go +++ b/internal/setup/setup_test.go @@ -768,6 +768,30 @@ var setupTests = []setupTest{{ }, }, }, +}, { + summary: "Maximum priority", + input: map[string]string{ + "chisel.yaml": ` + format: chisel-v1 + archives: + upper-limit: + version: 1 + suites: [main] + components: [main] + priority: 2147483647 + lower-limit: + version: 1 + suites: [main] + components: [main] + priority: -2147483648 + over-limit: + version: 1 + suites: [main] + components: [main] + priority: 2147483648 + `, + }, + relerror: "(?s).*\\bcannot unmarshal !!int `2147483648` into int32\\b.*", }} const defaultChiselYaml = ` diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index 84321376..999d48c0 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -72,8 +72,8 @@ func Run(options *RunOptions) error { } // Archives are ordered in descending order by priority. The - // default priority is 0 and the maximum allowed priority is - // the upper limit of int. + // default priority is 0 and the range of allowed priorities + // is the same as the range of the int32 data type. // // If a package to be downloaded exists in archive A and // archive B, and archive A has higher priority than archive @@ -111,7 +111,7 @@ func Run(options *RunOptions) error { if extractPackage == nil { var selectedVersion string var selectedArchive archive.Archive - currentPrio := math.MaxInt + var currentPrio int32 = math.MaxInt32 for _, currentArchive := range orderedArchives { if prio := currentArchive.Options().Priority; prio < currentPrio { if selectedVersion != "" {