From a01ee99493a8ffcc8c4869041f61d0c420aef092 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Mon, 3 Apr 2023 17:18:14 +0000 Subject: [PATCH] index: rework architecture filtering Signed-off-by: Ariadne Conill --- pkg/index/index.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/pkg/index/index.go b/pkg/index/index.go index 0504f78d2..3a759c9cc 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -134,6 +134,13 @@ func (ctx *Context) GenerateIndex() error { g.FirstErrorStore(fmt.Errorf("failed to parse package %s: %w", apkFile, err)) return } + + 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) + return + } + mtx.Lock() packages[i] = pkg mtx.Unlock() @@ -162,12 +169,6 @@ 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 @@ -180,19 +181,29 @@ func (ctx *Context) GenerateIndex() error { } } else { // indexFile not exists, we just create a new one - index = &apkrepo.ApkIndex{ - Packages: packages, + index = &apkrepo.ApkIndex{} + + for _, pkg := range packages { + if pkg != nil { + index.Packages = append(index.Packages, pkg) + } } } } else { - index = &apkrepo.ApkIndex{ - Packages: packages, + index = &apkrepo.ApkIndex{} + + for _, pkg := range packages { + if pkg != nil { + index.Packages = append(index.Packages, pkg) + } } } pkgNames := make([]string, 0, len(packages)) for _, p := range packages { - pkgNames = append(pkgNames, fmt.Sprintf("%s-%s", p.Name, p.Version)) + if p != nil { + pkgNames = append(pkgNames, fmt.Sprintf("%s-%s", p.Name, p.Version)) + } } ctx.Logger.Printf("generating index at %s with new packages: %v", ctx.IndexFile, pkgNames)