From c5d397c1f476c3c41d2db98fd740d43b5b7bc9ae Mon Sep 17 00:00:00 2001 From: Paul Mars Date: Thu, 9 Jul 2026 14:55:35 +0200 Subject: [PATCH 1/5] feat: prepare interface for store Signed-off-by: Paul Mars --- internal/slicer/slicer.go | 74 +++++++++++++++++++++++++++------- internal/slicer/slicer_test.go | 24 +++++++++++ 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index 6f4783b8..a2ab6032 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -41,6 +41,15 @@ type contentChecker struct { knownPaths map[string]pathData } +// pkgSource holds the resolved source for a package: its architecture and a +// fetch function returning the package reader and metadata. The fetch +// function is bound at resolution time, so callers are agnostic to whether +// the package comes from an archive or a store. +type pkgSource struct { + arch string + fetch func() (io.ReadSeekCloser, *archive.PackageInfo, error) +} + func (cc *contentChecker) checkMutable(path string) error { if !cc.knownPaths[path].mutable { return fmt.Errorf("cannot write file which is not mutable: %s", path) @@ -90,7 +99,7 @@ func Run(options *RunOptions) error { targetDir = filepath.Join(dir, targetDir) } - pkgArchive, err := selectPkgArchives(options.Archives, options.Selection) + pkgSources, err := resolvePkgSources(options.Archives, options.Selection) if err != nil { return err } @@ -108,12 +117,12 @@ func Run(options *RunOptions) error { extractPackage = make(map[string][]tarball.ExtractInfo) extract[slice.Package] = extractPackage } - arch := pkgArchive[slice.Package].Options().Arch + src := pkgSources[slice.Package] for targetPath, pathInfo := range slice.Contents { if targetPath == "" { continue } - if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, arch) { + if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, src.arch) { continue } if preferredPkg, ok := prefers[targetPath]; ok && preferredPkg.Name != slice.Package { @@ -153,7 +162,8 @@ func Run(options *RunOptions) error { continue } pkg := options.Selection.Release.Packages[slice.Package] - reader, info, err := pkgArchive[slice.Package].Fetch(pkg.RealName) + src := pkgSources[pkg] + reader, info, err := src.fetch() if err != nil { return err } @@ -270,9 +280,9 @@ func Run(options *RunOptions) error { // them to the appropriate slices. relPaths := map[string][]*setup.Slice{} for _, slice := range options.Selection.Slices { - arch := pkgArchive[slice.Package].Options().Arch + src := pkgSources[slice.Package] for relPath, pathInfo := range slice.Contents { - if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, arch) { + if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, src.arch) { continue } if pathInfo.Kind == setup.CopyPath || pathInfo.Kind == setup.GlobPath || @@ -490,10 +500,13 @@ func createFile(targetDir, relPath string, pathInfo setup.PathInfo) (*fsutil.Ent }) } -// selectPkgArchives selects the highest priority archive containing the package -// unless a particular archive is pinned within the slice definition file. It -// returns a map of archives indexed by package names. -func selectPkgArchives(archives map[string]archive.Archive, selection *setup.Selection) (map[string]archive.Archive, error) { +// resolvePkgSources determines the source for each package in the selection. +// For archive packages it selects the highest priority archive containing the +// package unless a particular archive is pinned within the slice definition +// file. For store packages it records a fetch function that returns an error +// until store support is implemented. It returns a map of pkgSource indexed by +// package names. +func resolvePkgSources(archives map[string]archive.Archive, selection *setup.Selection) (map[string]pkgSource, error) { sortedArchives := make([]*setup.Archive, 0, len(selection.Release.Archives)) for _, archive := range selection.Release.Archives { if archive.Priority < 0 { @@ -507,12 +520,20 @@ func selectPkgArchives(archives map[string]archive.Archive, selection *setup.Sel return b.Priority - a.Priority }) - pkgArchive := make(map[string]archive.Archive) + pkgSources := make(map[string]pkgSource) for _, s := range selection.Slices { - if _, ok := pkgArchive[s.Package]; ok { + if _, ok := pkgSources[s.Package]; ok { continue } pkg := selection.Release.Packages[s.Package] + if pkg.Store != "" { + pkgSources[pkg.Name] = pkgSource{ + fetch: func() (io.ReadSeekCloser, *archive.PackageInfo, error) { + return nil, nil, fmt.Errorf("cannot fetch package %q from store: store packages are not yet supported", pkg.Name) + }, + } + continue + } if pkg.Store != "" { return nil, fmt.Errorf("cannot fetch package %q from store %q: not implemented", pkg.Name, pkg.Store) @@ -538,7 +559,32 @@ func selectPkgArchives(archives map[string]archive.Archive, selection *setup.Sel if chosen == nil { return nil, fmt.Errorf("cannot find package %q in archive(s)", pkg.RealName) } - pkgArchive[pkg.Name] = chosen + chosenArchive := chosen + pkgSources[pkg.Name] = pkgSource{ + arch: chosen.Options().Arch, + fetch: func() (io.ReadSeekCloser, *archive.PackageInfo, error) { + return chosenArchive.Fetch(pkg.RealName) + }, + } } - return pkgArchive, nil + + // Until a store is implemented as a package source there is no proper way to + // determine the architecture for store packages. + // So relying on the fact that all packages in a selection share the same architecture, + // we can borrow it from any archive package that was already resolved. + var arch string + for _, src := range pkgSources { + if src.arch != "" { + arch = src.arch + break + } + } + for name, src := range pkgSources { + if src.arch == "" { + src.arch = arch + pkgSources[name] = src + } + } + + return pkgSources, nil } diff --git a/internal/slicer/slicer_test.go b/internal/slicer/slicer_test.go index d6ef9ca0..4e1e39d1 100644 --- a/internal/slicer/slicer_test.go +++ b/internal/slicer/slicer_test.go @@ -1994,6 +1994,30 @@ var slicerTests = []slicerTest{{ `, }, error: `cannot fetch package "bin-curl" from store "bin": not implemented`, +}, { + summary: "Store package fails as it is not yet supported", + slices: []setup.SliceKey{{"test-package", "myslice"}, {"bin-store-pkg", "myslice"}}, + arch: "amd64", + release: map[string]string{ + "chisel.yaml": testutil.DefaultChiselYamlWithStores, + "slices/mydir/test-package.yaml": ` + package: test-package + slices: + myslice: + contents: + /dir/file: + `, + "slices/mydir/store-pkg.yaml": ` + package: store-pkg + store: bin + default-track: stable + slices: + myslice: + contents: + /dir/store-file: + `, + }, + error: `cannot fetch package "bin-store-pkg" from store: store packages are not yet supported`, }} func (s *S) TestRun(c *C) { From f79521ea21a040baef490ea9987aab08d0d1d795 Mon Sep 17 00:00:00 2001 From: Paul Mars Date: Fri, 10 Jul 2026 09:59:59 +0200 Subject: [PATCH 2/5] fix: error fetching from the store Signed-off-by: Paul Mars --- internal/slicer/slicer.go | 8 ++------ internal/slicer/slicer_test.go | 20 ++------------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index a2ab6032..83ff84a7 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -162,7 +162,7 @@ func Run(options *RunOptions) error { continue } pkg := options.Selection.Release.Packages[slice.Package] - src := pkgSources[pkg] + src := pkgSources[pkg.Name] reader, info, err := src.fetch() if err != nil { return err @@ -529,16 +529,12 @@ func resolvePkgSources(archives map[string]archive.Archive, selection *setup.Sel if pkg.Store != "" { pkgSources[pkg.Name] = pkgSource{ fetch: func() (io.ReadSeekCloser, *archive.PackageInfo, error) { - return nil, nil, fmt.Errorf("cannot fetch package %q from store: store packages are not yet supported", pkg.Name) + return nil, nil, fmt.Errorf("cannot fetch package %q from store %q: not implemented", pkg.Name, pkg.Store) }, } continue } - if pkg.Store != "" { - return nil, fmt.Errorf("cannot fetch package %q from store %q: not implemented", pkg.Name, pkg.Store) - } - var candidates []*setup.Archive if pkg.Archive == "" { // If the package has not pinned any archive, choose the highest diff --git a/internal/slicer/slicer_test.go b/internal/slicer/slicer_test.go index 4e1e39d1..af107779 100644 --- a/internal/slicer/slicer_test.go +++ b/internal/slicer/slicer_test.go @@ -1978,23 +1978,7 @@ var slicerTests = []slicerTest{{ manifestPaths: map[string]string{ "/dir/file": "file 0644 cc55e2ec {test-package_third}", }, -}, { - summary: "Store package is not yet implemented", - slices: []setup.SliceKey{{"bin-curl", "bin"}}, - release: map[string]string{ - "chisel.yaml": testutil.DefaultChiselYamlWithStores, - "slices/curl.yaml": ` - package: curl - store: bin - default-track: latest - slices: - bin: - contents: - /usr/bin/curl: - `, - }, - error: `cannot fetch package "bin-curl" from store "bin": not implemented`, -}, { +},{ summary: "Store package fails as it is not yet supported", slices: []setup.SliceKey{{"test-package", "myslice"}, {"bin-store-pkg", "myslice"}}, arch: "amd64", @@ -2017,7 +2001,7 @@ var slicerTests = []slicerTest{{ /dir/store-file: `, }, - error: `cannot fetch package "bin-store-pkg" from store: store packages are not yet supported`, + error: `cannot fetch package "bin-store-pkg" from store "bin": not implemented`, }} func (s *S) TestRun(c *C) { From a2e22f27ee82997cf6305825a60b330b68f2612a Mon Sep 17 00:00:00 2001 From: Paul Mars Date: Fri, 10 Jul 2026 10:37:57 +0200 Subject: [PATCH 3/5] fix: cleaning Signed-off-by: Paul Mars --- internal/slicer/slicer.go | 14 ++++++-------- internal/slicer/slicer_test.go | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index 83ff84a7..ab510628 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -117,12 +117,12 @@ func Run(options *RunOptions) error { extractPackage = make(map[string][]tarball.ExtractInfo) extract[slice.Package] = extractPackage } - src := pkgSources[slice.Package] + arch := pkgSources[slice.Package].arch for targetPath, pathInfo := range slice.Contents { if targetPath == "" { continue } - if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, src.arch) { + if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, arch) { continue } if preferredPkg, ok := prefers[targetPath]; ok && preferredPkg.Name != slice.Package { @@ -162,8 +162,7 @@ func Run(options *RunOptions) error { continue } pkg := options.Selection.Release.Packages[slice.Package] - src := pkgSources[pkg.Name] - reader, info, err := src.fetch() + reader, info, err := pkgSources[pkg.Name].fetch() if err != nil { return err } @@ -280,9 +279,9 @@ func Run(options *RunOptions) error { // them to the appropriate slices. relPaths := map[string][]*setup.Slice{} for _, slice := range options.Selection.Slices { - src := pkgSources[slice.Package] + arch := pkgSources[slice.Package].arch for relPath, pathInfo := range slice.Contents { - if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, src.arch) { + if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, arch) { continue } if pathInfo.Kind == setup.CopyPath || pathInfo.Kind == setup.GlobPath || @@ -555,11 +554,10 @@ func resolvePkgSources(archives map[string]archive.Archive, selection *setup.Sel if chosen == nil { return nil, fmt.Errorf("cannot find package %q in archive(s)", pkg.RealName) } - chosenArchive := chosen pkgSources[pkg.Name] = pkgSource{ arch: chosen.Options().Arch, fetch: func() (io.ReadSeekCloser, *archive.PackageInfo, error) { - return chosenArchive.Fetch(pkg.RealName) + return chosen.Fetch(pkg.RealName) }, } } diff --git a/internal/slicer/slicer_test.go b/internal/slicer/slicer_test.go index af107779..eaedfa28 100644 --- a/internal/slicer/slicer_test.go +++ b/internal/slicer/slicer_test.go @@ -1978,8 +1978,8 @@ var slicerTests = []slicerTest{{ manifestPaths: map[string]string{ "/dir/file": "file 0644 cc55e2ec {test-package_third}", }, -},{ - summary: "Store package fails as it is not yet supported", +}, { + summary: "Store package fails as not yet implemented", slices: []setup.SliceKey{{"test-package", "myslice"}, {"bin-store-pkg", "myslice"}}, arch: "amd64", release: map[string]string{ From 2eb85d0aecd46e0a7d1fb2d3f8a378f9c4db41eb Mon Sep 17 00:00:00 2001 From: Paul Mars Date: Wed, 15 Jul 2026 15:52:47 +0200 Subject: [PATCH 4/5] feat: remove arch setting until store implementation Signed-off-by: Paul Mars --- internal/slicer/slicer.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index ab510628..fcc16d67 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -527,6 +527,7 @@ func resolvePkgSources(archives map[string]archive.Archive, selection *setup.Sel pkg := selection.Release.Packages[s.Package] if pkg.Store != "" { pkgSources[pkg.Name] = pkgSource{ + // TODO: set the arch when implementing fetching from the store. fetch: func() (io.ReadSeekCloser, *archive.PackageInfo, error) { return nil, nil, fmt.Errorf("cannot fetch package %q from store %q: not implemented", pkg.Name, pkg.Store) }, @@ -561,24 +562,5 @@ func resolvePkgSources(archives map[string]archive.Archive, selection *setup.Sel }, } } - - // Until a store is implemented as a package source there is no proper way to - // determine the architecture for store packages. - // So relying on the fact that all packages in a selection share the same architecture, - // we can borrow it from any archive package that was already resolved. - var arch string - for _, src := range pkgSources { - if src.arch != "" { - arch = src.arch - break - } - } - for name, src := range pkgSources { - if src.arch == "" { - src.arch = arch - pkgSources[name] = src - } - } - return pkgSources, nil } From 3004a6eff32ba8b8dd5c61177cdf450fc85a024e Mon Sep 17 00:00:00 2001 From: Paul Mars Date: Wed, 15 Jul 2026 15:57:02 +0200 Subject: [PATCH 5/5] test: refine Signed-off-by: Paul Mars --- internal/slicer/slicer_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/slicer/slicer_test.go b/internal/slicer/slicer_test.go index eaedfa28..954602de 100644 --- a/internal/slicer/slicer_test.go +++ b/internal/slicer/slicer_test.go @@ -1979,7 +1979,7 @@ var slicerTests = []slicerTest{{ "/dir/file": "file 0644 cc55e2ec {test-package_third}", }, }, { - summary: "Store package fails as not yet implemented", + summary: "Store package fetching not yet implemented", slices: []setup.SliceKey{{"test-package", "myslice"}, {"bin-store-pkg", "myslice"}}, arch: "amd64", release: map[string]string{ @@ -1994,7 +1994,7 @@ var slicerTests = []slicerTest{{ "slices/mydir/store-pkg.yaml": ` package: store-pkg store: bin - default-track: stable + default-track: 3.1 slices: myslice: contents: