diff --git a/routers/api/packages/arch/arch.go b/routers/api/packages/arch/arch.go index 1596fe7061..3f0aa58691 100644 --- a/routers/api/packages/arch/arch.go +++ b/routers/api/packages/arch/arch.go @@ -155,13 +155,13 @@ func Get(ctx *context.Context) { // Packages are stored in different way from pacman databases, and loaded // with LoadPackageFile function. if strings.HasSuffix(file, "tar.zst") || strings.HasSuffix(file, "zst.sig") { - pkgdata, err := arch_service.LoadFile(ctx, distro, file) + pkg, err := arch_service.GetFileObject(ctx, distro, file) if err != nil { apiError(ctx, http.StatusNotFound, err) return } - ctx.ServeContent(bytes.NewReader(pkgdata), &context.ServeHeaderOptions{ + ctx.ServeContent(pkg, &context.ServeHeaderOptions{ Filename: file, CacheDuration: time.Minute * 5, }) diff --git a/services/packages/arch/db_manager.go b/services/packages/arch/db_manager.go index f5c3360d87..89ec8691e6 100644 --- a/services/packages/arch/db_manager.go +++ b/services/packages/arch/db_manager.go @@ -6,7 +6,6 @@ package arch import ( "bytes" "fmt" - "io" "sort" "strings" @@ -19,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/packages" "code.gitea.io/gitea/modules/packages/arch" + "code.gitea.io/gitea/modules/storage" pkg_service "code.gitea.io/gitea/services/packages" ) @@ -107,7 +107,7 @@ func SaveFile(ctx *context.Context, p *SaveFileParams) (int64, error) { // Get data related to provided file name and distribution, and update download // counter if actual package file is retrieved from database. -func LoadFile(ctx *context.Context, distro, file string) ([]byte, error) { +func GetFileObject(ctx *context.Context, distro, file string) (storage.Object, error) { db := db.GetEngine(ctx) pkgfile := &pkg_model.PackageFile{CompositeKey: distro + "-" + file} @@ -131,12 +131,7 @@ func LoadFile(ctx *context.Context, distro, file string) ([]byte, error) { cs := packages.NewContentStore() - obj, err := cs.Get(packages.BlobHash256Key(blob.HashSHA256)) - if err != nil { - return nil, err - } - - return io.ReadAll(obj) + return cs.Get(packages.BlobHash256Key(blob.HashSHA256)) } // Automatically connect repository to pushed package, if package with provided