diff --git a/docs/md/melange_index.md b/docs/md/melange_index.md index d757a687e..d98748a0f 100644 --- a/docs/md/melange_index.md +++ b/docs/md/melange_index.md @@ -28,6 +28,7 @@ melange index [flags] ### Options ``` + -a, --arch string Index only packages which match the expected architecture -h, --help help for index -o, --output string Output generated index to FILE (default "APKINDEX.tar.gz") ``` diff --git a/pkg/cli/index.go b/pkg/cli/index.go index bda1181da..e4ec6b5b3 100644 --- a/pkg/cli/index.go +++ b/pkg/cli/index.go @@ -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", @@ -32,6 +33,7 @@ func Index() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { options := []index.Option{ index.WithIndexFile(apkIndexFilename), + index.WithExpectedArch(expectedArch), index.WithPackageFiles(args), } @@ -39,6 +41,7 @@ func Index() *cobra.Command { }, } 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 } diff --git a/pkg/index/index.go b/pkg/index/index.go index d877b57af..0504f78d2 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -35,6 +35,7 @@ type Context struct { MergeIndexFileFlag bool SigningKey string Logger *log.Logger + ExpectedArch string } type Option func(*Context) error @@ -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{}, @@ -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