Repository navigation
feat: abstract interactions with archive/store #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
upils
wants to merge
25
commits into
canonical:main
Choose a base branch
from
upils:slicer-source-interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c5d397c
feat: prepare interface for store
upils f79521e
fix: error fetching from the store
upils a2e22f2
fix: cleaning
upils 2eb85d0
feat: remove arch setting until store implementation
upils 3004a6e
test: refine
upils ed0e070
refactor: adopt alternative approach
upils 268501e
style: remove unused track and risk
upils 107103d
fix: rework fetcher interface
upils 1249e7b
Merge branch 'main' into slicer-source-interface
upils 4cfed24
refactor: use the manifestutil.PackageInfo interface
upils 7b124b3
test: remove redundant tests
upils 076ff37
style: renaming and tests simplification
upils eaddfd9
fix: revert unintended changes
upils bb39d06
docs: use package slices file term
upils b930f97
test: revert unrelated changes
upils 8c24bda
docs: clean useless comment
upils a13c637
fix: apply review comments
upils 3655843
fix: revert unwanted changes
upils a81c9a7
fix: move out fix for package naming collision
upils b932d17
fix: simplify arch check in Run
upils 1a997ea
docs: fix comment
upils aa574b9
fix: refine abstraction
upils aac4ef1
style: align name with project convention
upils 8c63924
fix: keep the diff focus on the added abstraction
upils 3cdef0a
docs: remove useless comment
upils File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package slicer | ||
|
|
||
| import ( | ||
| "io" | ||
|
|
||
| "github.com/canonical/chisel/internal/archive" | ||
| "github.com/canonical/chisel/internal/cache" | ||
| ) | ||
|
|
||
| // RemotePackageInfo describes a package as reported by its provider. | ||
| type RemotePackageInfo struct { | ||
| Name string | ||
| Version string | ||
| Revision int | ||
| Arch string | ||
| Store string | ||
| DigestKind cache.DigestKind | ||
| Digest string | ||
| } | ||
|
|
||
| func (p *RemotePackageInfo) PkgName() string { return p.Name } | ||
| func (p *RemotePackageInfo) PkgVersion() string { return p.Version } | ||
| func (p *RemotePackageInfo) PkgRevision() int { return p.Revision } | ||
| func (p *RemotePackageInfo) PkgArch() string { return p.Arch } | ||
| func (p *RemotePackageInfo) PkgStore() string { return p.Store } | ||
| func (p *RemotePackageInfo) PkgDigestKind() cache.DigestKind { return p.DigestKind } | ||
| func (p *RemotePackageInfo) PkgDigest() string { return p.Digest } | ||
|
|
||
| // PackageRemote represents the remote from which a package is obtained. | ||
| type PackageRemote interface { | ||
| // Arch returns the architecture the remote serves packages for, which is | ||
| // the target architecture used to request the package, not the | ||
| // architecture of the fetched package itself (which may be "all", for | ||
| // example). | ||
| Arch() string | ||
| Fetch() (io.ReadSeekCloser, *RemotePackageInfo, error) | ||
| } | ||
|
|
||
| var _ PackageRemote = (*archiveRemote)(nil) | ||
|
|
||
| type archiveRemote struct { | ||
| archive archive.Archive | ||
| name string | ||
| } | ||
|
|
||
| func (d *archiveRemote) Arch() string { | ||
| return d.archive.Options().Arch | ||
| } | ||
|
|
||
| func (d *archiveRemote) Fetch() (io.ReadSeekCloser, *RemotePackageInfo, error) { | ||
| reader, info, err := d.archive.Fetch(d.name) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| return reader, &RemotePackageInfo{ | ||
| Name: info.Name, | ||
| Version: info.Version, | ||
| Arch: info.Arch, | ||
| DigestKind: cache.SHA256, | ||
| Digest: info.SHA256, | ||
| }, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,7 @@ func Run(options *RunOptions) error { | |
| targetDir = filepath.Join(dir, targetDir) | ||
| } | ||
|
|
||
| pkgArchive, err := selectPkgArchives(options.Archives, options.Selection) | ||
| pkgRemotes, err := selectPkgRemotes(options.Archives, options.Selection) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Note to reviewer]: This was pluralized on purpose to avoid confusion with a single PackageRemote instance. |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -108,7 +108,7 @@ func Run(options *RunOptions) error { | |
| extractPackage = make(map[string][]tarball.ExtractInfo) | ||
| extract[slice.Package] = extractPackage | ||
| } | ||
| arch := pkgArchive[slice.Package].Options().Arch | ||
| arch := pkgRemotes[slice.Package].Arch() | ||
| for targetPath, pathInfo := range slice.Contents { | ||
| if targetPath == "" { | ||
| continue | ||
|
|
@@ -153,7 +153,7 @@ func Run(options *RunOptions) error { | |
| continue | ||
| } | ||
| pkg := options.Selection.Release.Packages[slice.Package] | ||
| reader, info, err := pkgArchive[slice.Package].Fetch(pkg.RealName) | ||
| reader, info, err := pkgRemotes[pkg.Name].Fetch() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -270,7 +270,7 @@ 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 | ||
| arch := pkgRemotes[slice.Package].Arch() | ||
| for relPath, pathInfo := range slice.Contents { | ||
| if len(pathInfo.Arch) > 0 && !slices.Contains(pathInfo.Arch, arch) { | ||
| continue | ||
|
|
@@ -490,10 +490,12 @@ 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) { | ||
| // selectPkgRemotes determines the remote for each package in the selection. | ||
| // For packages from an archive it selects the highest priority archive | ||
| // containing the package unless a particular archive is pinned within the | ||
| // package slices file. Packages from a store are not supported yet. | ||
| // It returns a map of PackageRemote indexed by package names. | ||
| func selectPkgRemotes(archives map[string]archive.Archive, selection *setup.Selection) (map[string]PackageRemote, error) { | ||
| sortedArchives := make([]*setup.Archive, 0, len(selection.Release.Archives)) | ||
| for _, archive := range selection.Release.Archives { | ||
| if archive.Priority < 0 { | ||
|
|
@@ -507,9 +509,9 @@ func selectPkgArchives(archives map[string]archive.Archive, selection *setup.Sel | |
| return b.Priority - a.Priority | ||
| }) | ||
|
|
||
| pkgArchive := make(map[string]archive.Archive) | ||
| pkgRemotes := make(map[string]PackageRemote) | ||
| for _, s := range selection.Slices { | ||
| if _, ok := pkgArchive[s.Package]; ok { | ||
| if _, ok := pkgRemotes[s.Package]; ok { | ||
| continue | ||
| } | ||
| pkg := selection.Release.Packages[s.Package] | ||
|
|
@@ -538,7 +540,10 @@ 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 | ||
| pkgRemotes[pkg.Name] = &archiveRemote{ | ||
| archive: chosen, | ||
| name: pkg.RealName, | ||
| } | ||
| } | ||
| return pkgArchive, nil | ||
| return pkgRemotes, nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Note to reviewer]: Following your suggestion, the
archive.PackageInfo(and the futurestore.PackageInfo) does not satisfy the interface defined by manifestutil anymore, butRemotePackageInfodoes. The Fetch method below does the fetching and converts the received PackageInfo.