replaced bytes.Buffer with packages.HashedBuffer to return working io.ReadSeeker implementation

This commit is contained in:
Danila Fominykh 2023-09-25 18:42:48 -03:00
parent 946d8cc9ea
commit 4656b3b958
No known key found for this signature in database
GPG Key ID: 1134F8EBF98AA06F
3 changed files with 9 additions and 8 deletions

View File

@ -6,7 +6,6 @@ package arch
import ( import (
"archive/tar" "archive/tar"
"bufio" "bufio"
"bytes"
"compress/gzip" "compress/gzip"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
@ -215,10 +214,13 @@ func rmEmptyStrings(s []string) []string {
} }
// Create pacman database archive based on provided package metadata structs. // Create pacman database archive based on provided package metadata structs.
func CreatePacmanDb(entries map[string][]byte) ([]byte, error) { func CreatePacmanDb(entries map[string][]byte) (io.ReadSeeker, error) {
var out bytes.Buffer out, err := pkg_module.NewHashedBuffer()
if err != nil {
return nil, err
}
gw := gzip.NewWriter(&out) gw := gzip.NewWriter(out)
tw := tar.NewWriter(gw) tw := tar.NewWriter(gw)
for name, content := range entries { for name, content := range entries {
@ -244,5 +246,5 @@ func CreatePacmanDb(entries map[string][]byte) ([]byte, error) {
tw.Close() tw.Close()
gw.Close() gw.Close()
return out.Bytes(), nil return out, nil
} }

View File

@ -4,7 +4,6 @@
package arch package arch
import ( import (
"bytes"
"encoding/hex" "encoding/hex"
"io" "io"
"net/http" "net/http"
@ -160,7 +159,7 @@ func Get(ctx *context.Context) {
return return
} }
ctx.ServeContent(bytes.NewReader(db), &context.ServeHeaderOptions{ ctx.ServeContent(db, &context.ServeHeaderOptions{
Filename: file, Filename: file,
}) })
return return

View File

@ -77,7 +77,7 @@ func RepoConnect(ctx *context.Context, owner, repo string, pkgid int64) error {
// requested combination of architecture and distribution. When/If the first // requested combination of architecture and distribution. When/If the first
// compatible version is found, related desc file will be loaded from database // compatible version is found, related desc file will be loaded from database
// and added to resulting .db.tar.gz archive. // and added to resulting .db.tar.gz archive.
func CreatePacmanDb(ctx *context.Context, owner, arch, distro string) ([]byte, error) { func CreatePacmanDb(ctx *context.Context, owner, arch, distro string) (io.ReadSeeker, error) {
pkgs, err := pkg_model.GetPackagesByType(ctx, ctx.Package.Owner.ID, pkg_model.TypeArch) pkgs, err := pkg_model.GetPackagesByType(ctx, ctx.Package.Owner.ID, pkg_model.TypeArch)
if err != nil { if err != nil {
return nil, err return nil, err