mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-01 07:10:36 +00:00
fix(packages): serve noarch Alpine index for any requested architecture (#38479)
Fixes #38456 ## Problem The Alpine package registry serves one `APKINDEX.tar.gz` per architecture. When a repository contains only `noarch` packages (no architecture-specific packages), only the `noarch` index is built. Because `apk` substitutes `$ARCH` with the host architecture and requests e.g. `x86_64/APKINDEX.tar.gz`, such a repository returned HTTP 404 and was unusable, matching the report in #38456. ## Fix `GetRepositoryFile` now falls back to the `noarch` index when the requested architecture has no index of its own, mirroring the fallback already present in the sibling `DownloadPackageFile` handler. `noarch` packages are installable on every architecture, so serving them for any requested architecture is correct. The index-build side is unchanged; only the serving path gains the fallback, so mixed repositories (which already merge `noarch` into each per-architecture index) are unaffected. ## AI assistance disclosure This change was implemented with the help of an AI coding assistant, which gitea's CONTRIBUTING.md explicitly welcomes when disclosed. I have reviewed the change, understand it, and can explain and defend it. ## Tests Added a `NoArchOnly` subtest to `TestPackageAlpine` that publishes only a `noarch` package to a fresh repository and asserts that `GET .../x86_64/APKINDEX.tar.gz` now returns `200` (previously `404`) and that the served index lists the noarch package. Verified locally with `go build`/`go vet` on the changed package and a compile of the integration test package (`go test -c`); the full integration run relies on CI. --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -67,15 +67,34 @@ func GetRepositoryFile(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
branch := ctx.PathParam("branch")
|
||||
repository := ctx.PathParam("repository")
|
||||
architecture := ctx.PathParam("architecture")
|
||||
|
||||
s, u, pf, err := packages_service.OpenFileForDownloadByPackageVersion(
|
||||
ctx,
|
||||
pv,
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: alpine_service.IndexArchiveFilename,
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", ctx.PathParam("branch"), ctx.PathParam("repository"), ctx.PathParam("architecture")),
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", branch, repository, architecture),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
// A repository that only contains "noarch" packages has no per-architecture
|
||||
// index. Since noarch packages are installable on every architecture, fall
|
||||
// back to the noarch index so clients requesting their own architecture
|
||||
// (e.g. x86_64) can still discover them.
|
||||
if errors.Is(err, util.ErrNotExist) && architecture != alpine_module.NoArch {
|
||||
s, u, pf, err = packages_service.OpenFileForDownloadByPackageVersion(
|
||||
ctx,
|
||||
pv,
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: alpine_service.IndexArchiveFilename,
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", branch, repository, alpine_module.NoArch),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
|
||||
Reference in New Issue
Block a user