From 3f7a32c8e9bdaeeb36bf33f01d2cefb91765d413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Virtus?= Date: Wed, 31 May 2023 14:08:16 +0200 Subject: [PATCH] Make archive priority int32 Archive priority is currently defined as int. This can make chisel.yaml with very high/low priorities non-portable, e.g. from amd64 to arm32. Change archive priority definition to int32 data type. --- internal/archive/archive.go | 2 +- internal/setup/setup.go | 4 ++-- internal/setup/setup_test.go | 24 ++++++++++++++++++++++++ internal/slicer/slicer.go | 6 +++--- 4 files changed, 30 insertions(+), 6 deletions(-) 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 != "" {