Skip to content

Commit f68456f

Browse files
fix bugs from forgejo
1 parent ce73234 commit f68456f

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

routers/api/packages/arch/arch.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ func PushPackage(ctx *context.Context) {
165165
apiError(ctx, http.StatusInternalServerError, err)
166166
return
167167
}
168+
if p.FileMetadata.Arch == "any" {
169+
if err = arch_service.BuildCustomRepositoryFiles(ctx, ctx.Package.Owner.ID, group); err != nil {
170+
apiError(ctx, http.StatusInternalServerError, err)
171+
return
172+
}
173+
}
168174
ctx.Status(http.StatusCreated)
169175
}
170176

services/packages/arch/repository.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ func GetPackageDBFile(ctx context.Context, group, arch string, ownerID int64, si
285285
fileName = fmt.Sprintf("%s.db.sig", arch)
286286
}
287287
file, err := packages_model.GetFileForVersionByName(ctx, pv.ID, fileName, group)
288+
// failback to any db
289+
if errors.Is(err, util.ErrNotExist) && arch != "any" {
290+
fileName = "any.db"
291+
if signFile {
292+
fileName = "any.db.sig"
293+
}
294+
file, err = packages_model.GetFileForVersionByName(ctx, pv.ID, fileName, group)
295+
}
288296
if err != nil {
289297
return nil, nil, nil, err
290298
}

tests/integration/api_packages_arch_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,30 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
336336
MakeRequest(t, req, http.StatusNoContent)
337337
}
338338
})
339+
t.Run("Package Arch Test", func(t *testing.T) {
340+
defer tests.PrintCurrentTest(t)()
341+
req := NewRequestWithBody(t, "PUT", rootURL, bytes.NewReader(pkgs["any"])).
342+
AddBasicAuth(user.Name)
343+
MakeRequest(t, req, http.StatusCreated)
344+
345+
req = NewRequest(t, "GET", rootURL+"/x86_64/base.db")
346+
respPkg := MakeRequest(t, req, http.StatusOK)
347+
348+
files, err := listTarGzFiles(respPkg.Body.Bytes())
349+
require.NoError(t, err)
350+
require.Len(t, files, 1)
351+
352+
req = NewRequestWithBody(t, "PUT", rootURL, bytes.NewReader(pkgs["otherXZ"])).
353+
AddBasicAuth(user.Name)
354+
MakeRequest(t, req, http.StatusCreated)
355+
356+
req = NewRequest(t, "GET", rootURL+"/x86_64/base.db")
357+
respPkg = MakeRequest(t, req, http.StatusOK)
358+
359+
files, err = listTarGzFiles(respPkg.Body.Bytes())
360+
require.NoError(t, err)
361+
require.Len(t, files, 2)
362+
})
339363
}
340364

341365
func getProperty(data, key string) string {

0 commit comments

Comments
 (0)