Skip to content

Commit 21973dc

Browse files
author
Rafid Bin Mostofa
committed
fix: ignore negative priority archives
If an archive has a negative priority, ignore it while choosing the best archive for a package. Unless, a package particularly asks for that particular archive with negative priority. In that case, that archive is chosen for the package.
1 parent 0b00dc8 commit 21973dc

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎internal/slicer/slicer.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ func selectPkgArchives(archives map[string]archive.Archive, selection *setup.Sel
398398
// Sort the archives by their priority value.
399399
releaseArchives := make([]*setup.Archive, 0, len(selection.Release.Archives))
400400
for _, archive := range selection.Release.Archives {
401+
if archive.Priority < 0 {
402+
// Ignore negative priority archives unless a package specifically
403+
// asks for it with the "archive" field.
404+
continue
405+
}
401406
releaseArchives = append(releaseArchives, archive)
402407
}
403408
slices.SortFunc(releaseArchives, func(a, b *setup.Archive) int {

‎internal/slicer/slicer_test.go‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,86 @@ var slicerTests = []slicerTest{{
992992
`,
993993
},
994994
error: "slice package \"test-package\" missing from archive\\(s\\)",
995+
}, {
996+
summary: "Negative priority archives are ignored, unless asked by package",
997+
slices: []setup.SliceKey{{"test-package", "myslice"}},
998+
archives: map[string]*testArchive{
999+
"foo": {
1000+
pkgs: map[string][]byte{
1001+
"test-package": testutil.MustMakeDeb([]testutil.TarEntry{
1002+
testutil.Reg(0644, "./file", "from foo"),
1003+
}),
1004+
},
1005+
},
1006+
},
1007+
release: map[string]string{
1008+
"chisel.yaml": `
1009+
format: chisel-v1
1010+
archives:
1011+
foo:
1012+
version: 22.04
1013+
components: [main, universe]
1014+
default: true
1015+
priority: -20
1016+
v1-public-keys: [test-key]
1017+
v1-public-keys:
1018+
test-key:
1019+
id: ` + testKey.ID + `
1020+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
1021+
`,
1022+
"slices/mydir/test-package.yaml": `
1023+
package: test-package
1024+
slices:
1025+
myslice:
1026+
contents:
1027+
/file:
1028+
`,
1029+
},
1030+
// Although test-package exists in archive "foo", the archive was ignored
1031+
// due to having a negative priority.
1032+
error: "slice package \"test-package\" missing from archive\\(s\\)",
1033+
}, {
1034+
summary: "Negative priority archives are asked by package",
1035+
slices: []setup.SliceKey{{"test-package", "myslice"}},
1036+
archives: map[string]*testArchive{
1037+
"foo": {
1038+
pkgs: map[string][]byte{
1039+
"test-package": testutil.MustMakeDeb([]testutil.TarEntry{
1040+
testutil.Reg(0644, "./file", "from foo"),
1041+
}),
1042+
},
1043+
},
1044+
},
1045+
release: map[string]string{
1046+
"chisel.yaml": `
1047+
format: chisel-v1
1048+
archives:
1049+
foo:
1050+
version: 22.04
1051+
components: [main, universe]
1052+
default: true
1053+
priority: -20
1054+
v1-public-keys: [test-key]
1055+
v1-public-keys:
1056+
test-key:
1057+
id: ` + testKey.ID + `
1058+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
1059+
`,
1060+
"slices/mydir/test-package.yaml": `
1061+
package: test-package
1062+
archive: foo
1063+
slices:
1064+
myslice:
1065+
contents:
1066+
/file:
1067+
`,
1068+
},
1069+
filesystem: map[string]string{
1070+
"/file": "file 0644 7a3e00f5",
1071+
},
1072+
report: map[string]string{
1073+
"/file": "file 0644 7a3e00f5 {test-package_myslice}",
1074+
},
9951075
}, {
9961076
summary: "Multiple slices of same package",
9971077
slices: []setup.SliceKey{

0 commit comments

Comments
 (0)