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

index: rework architecture filtering #375

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Changes from all 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
33 changes: 22 additions & 11 deletions pkg/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down