Skip to content
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

Add --arch to melange index to skip packages with the wrong arch #372

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/cli/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

func Index() *cobra.Command {
var apkIndexFilename string
var expectedArch string
cmd := &cobra.Command{
Use: "index",
Short: "Creates a repository index from a list of package files",
Expand All @@ -32,13 +33,15 @@ func Index() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
options := []index.Option{
index.WithIndexFile(apkIndexFilename),
index.WithExpectedArch(expectedArch),
index.WithPackageFiles(args),
}

return IndexCmd(cmd.Context(), options...)
},
}
cmd.Flags().StringVarP(&apkIndexFilename, "output", "o", "APKINDEX.tar.gz", "Output generated index to FILE")
cmd.Flags().StringVarP(&expectedArch, "arch", "a", "", "Index only packages which match the expected architecture")
return cmd
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Context struct {
MergeIndexFileFlag bool
SigningKey string
Logger *log.Logger
ExpectedArch string
}

type Option func(*Context) error
Expand Down Expand Up @@ -86,6 +87,15 @@ func WithSigningKey(signingKey string) Option {
}
}

// WithExpectedArch sets the expected package architecture. Any packages with
// an unexpected architecture will not be indexed.
func WithExpectedArch(expectedArch string) Option {
return func(ctx *Context) error {
ctx.ExpectedArch = expectedArch
return nil
}
}

func New(opts ...Option) (*Context, error) {
ctx := Context{
PackageFiles: []string{},
Expand Down Expand Up @@ -151,6 +161,13 @@ func (ctx *Context) GenerateIndex() error {

for _, pkg := range packages {
found := false

if ctx.ExpectedArch != "" && pkg.Arch != ctx.ExpectedArch {
ctx.Logger.Printf("WARNING: %s-%s: found unexpected architecture %s, expecting %s",
pkg.Name, pkg.Version, pkg.Arch, ctx.ExpectedArch)
continue
}

for _, p := range index.Packages {
if pkg.Name == p.Name && pkg.Version == p.Version {
found = true
Expand Down