Skip to content

Commit

Permalink
Make archive priority int32
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
woky committed Oct 9, 2023
1 parent d8c76b1 commit 438f23a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Options struct {
Suites []string
Components []string
CacheDir string
Priority int
Priority int32
}

func Open(options *Options) (Archive, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,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 = `
Expand Down
6 changes: 3 additions & 3 deletions internal/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit 438f23a

Please sign in to comment.