mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-04 15:54:57 +00:00
fix(packages): serve empty conda noarch repodata when no noarch packages exist (#40582)
Conda (and libmamba) require every valid channel to serve `noarch/repodata.json` and `noarch/repodata.json.bz2` even when empty, while treating 404 on platform-specific subdirs as empty. Previously `EnumeratePackages` returned 404 whenever no package files existed for the requested subdir, causing `conda install` to fail with a 404 on `noarch/repodata.json` whenever a channel only contained platform-specific packages (e.g. `linux-64`). Return HTTP 200 with an empty `RepoData` payload when the requested subdir is `noarch` and no files exist, while keeping 404 for empty non-`noarch` subdirs. Fixes: https://github.com/go-gitea/gitea/issues/25554 Assisted-by: Claude Code:gemini-4-neon
This commit is contained in:
1 parent
6ab12548be
commit
2256e819c9
2 files changed
+24
-1
No files matched your search
@@ -23,6 +23,8 @@ import (
|
||||
"github.com/dsnet/compress/bzip2"
|
||||
)
|
||||
|
||||
const noarchSubdir = "noarch"
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.JSON(status, struct {
|
||||
@@ -99,7 +101,7 @@ func EnumeratePackages(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(pfs) == 0 {
|
||||
if len(pfs) == 0 && repoData.Info.Subdir != noarchSubdir { // Conda requires noarch/repodata.json to exist even when empty
|
||||
apiError(ctx, http.StatusNotFound, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -239,5 +239,26 @@ func TestPackageConda(t *testing.T) {
|
||||
assert.Empty(t, packageInfo.Dependencies)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", root+"/empty-channel/noarch/repodata.json")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
result := DecodeJSON(t, resp, &RepoData{})
|
||||
assert.Equal(t, &RepoData{
|
||||
Info: Info{Subdir: "noarch"},
|
||||
Packages: map[string]*PackageInfo{},
|
||||
PackagesConda: map[string]*PackageInfo{},
|
||||
Removed: map[string]*PackageInfo{},
|
||||
}, result)
|
||||
|
||||
req = NewRequest(t, "GET", root+"/empty-channel/noarch/repodata.json.bz2")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
assert.Equal(t, "application/x-bzip2", resp.Header().Get("Content-Type"))
|
||||
|
||||
req = NewRequest(t, "GET", root+"/linux-64/repodata.json")
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user