From fa307f06ac5cb41b8eb61d709b499bd92fb01533 Mon Sep 17 00:00:00 2001 From: dragon Date: Mon, 21 Oct 2024 10:08:57 +0800 Subject: [PATCH] fix arch pkg (cherry picked from commit 95c7599db5f5fb3546029bec22ca6126af81ad83) --- routers/api/packages/arch/arch.go | 9 ++++++-- services/packages/arch/repository.go | 12 +++++++++-- tests/integration/api_packages_arch_test.go | 24 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/routers/api/packages/arch/arch.go b/routers/api/packages/arch/arch.go index 15fcc37c70..ecd2281884 100644 --- a/routers/api/packages/arch/arch.go +++ b/routers/api/packages/arch/arch.go @@ -173,6 +173,12 @@ func PushPackage(ctx *context.Context) { apiError(ctx, http.StatusInternalServerError, err) return } + if p.FileMetadata.Arch == "any" { + if err = arch_service.BuildCustomRepositoryFiles(ctx, ctx.Package.Owner.ID, group); err != nil { + apiError(ctx, http.StatusInternalServerError, err) + return + } + } ctx.Status(http.StatusCreated) } @@ -197,8 +203,7 @@ func GetPackageOrDB(ctx *context.Context) { } if archDBOrSig.MatchString(file) { - pkg, u, pf, err := arch_service.GetPackageDBFile(ctx, group, arch, ctx.Package.Owner.ID, - strings.HasSuffix(file, ".sig")) + pkg, u, pf, err := arch_service.GetPackageDBFile(ctx, ctx.Package.Owner.ID, group, arch, strings.HasSuffix(file, ".sig")) if err != nil { if errors.Is(err, util.ErrNotExist) { apiError(ctx, http.StatusNotFound, err) diff --git a/services/packages/arch/repository.go b/services/packages/arch/repository.go index 58433ab5c2..763a0a2102 100644 --- a/services/packages/arch/repository.go +++ b/services/packages/arch/repository.go @@ -273,16 +273,24 @@ func GetPackageFile(ctx context.Context, group, file string, ownerID int64) (io. return packages_service.GetPackageFileStream(ctx, pkgFile) } -func GetPackageDBFile(ctx context.Context, group, arch string, ownerID int64, signFile bool) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) { +func GetPackageDBFile(ctx context.Context, ownerID int64, group, arch string, sigFile bool) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) { pv, err := GetOrCreateRepositoryVersion(ctx, ownerID) if err != nil { return nil, nil, nil, err } fileName := fmt.Sprintf("%s.db", arch) - if signFile { + if sigFile { fileName = fmt.Sprintf("%s.db.sig", arch) } file, err := packages_model.GetFileForVersionByName(ctx, pv.ID, fileName, group) + // fail back to any db + if errors.Is(err, util.ErrNotExist) && arch != "any" { + fileName = "any.db" + if sigFile { + fileName = "any.db.sig" + } + file, err = packages_model.GetFileForVersionByName(ctx, pv.ID, fileName, group) + } if err != nil { return nil, nil, nil, err } diff --git a/tests/integration/api_packages_arch_test.go b/tests/integration/api_packages_arch_test.go index 2cf0186416..8651af4a58 100644 --- a/tests/integration/api_packages_arch_test.go +++ b/tests/integration/api_packages_arch_test.go @@ -336,6 +336,30 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA MakeRequest(t, req, http.StatusNoContent) } }) + t.Run("Package Arch Test", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + req := NewRequestWithBody(t, "PUT", rootURL, bytes.NewReader(pkgs["any"])). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusCreated) + + req = NewRequest(t, "GET", rootURL+"/x86_64/base.db") + respPkg := MakeRequest(t, req, http.StatusOK) + + files, err := listTarGzFiles(respPkg.Body.Bytes()) + require.NoError(t, err) + require.Len(t, files, 1) + + req = NewRequestWithBody(t, "PUT", rootURL, bytes.NewReader(pkgs["otherXZ"])). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusCreated) + + req = NewRequest(t, "GET", rootURL+"/x86_64/base.db") + respPkg = MakeRequest(t, req, http.StatusOK) + + files, err = listTarGzFiles(respPkg.Body.Bytes()) + require.NoError(t, err) + require.Len(t, files, 2) + }) } func getProperty(data, key string) string {