fix typo and errors

pull/31037/head
dragon 2 months ago
parent d7373b531a
commit 5c2625a989
  1. 1
      modules/packages/arch/metadata.go
  2. 17
      services/packages/arch/repository.go
  3. 3
      tests/integration/api_packages_arch_test.go

@ -140,6 +140,7 @@ func ParsePackage(r *packages.HashedBuffer) (*Package, error) {
case ".PKGINFO":
pkg, err = ParsePackageInfo(tarballType, f)
if err != nil {
_ = f.Close()
return nil, err
}
case ".MTREE":

@ -175,15 +175,18 @@ func createDB(ctx context.Context, ownerID int64, group, arch string) (*packages
if err != nil {
return nil, err
}
defer db.Close()
gw := gzip.NewWriter(db)
defer gw.Close()
tw := tar.NewWriter(gw)
defer tw.Close()
count := 0
for _, pkg := range pkgs {
versions, err := packages_model.GetVersionsByPackageName(
ctx, ownerID, packages_model.TypeArch, pkg.Name,
)
if err != nil {
return nil, errors.Join(tw.Close(), gw.Close(), db.Close(), err)
return nil, err
}
sort.Slice(versions, func(i, j int) bool {
return versions[i].CreatedUnix > versions[j].CreatedUnix
@ -192,7 +195,7 @@ func createDB(ctx context.Context, ownerID int64, group, arch string) (*packages
for _, ver := range versions {
files, err := packages_model.GetFilesByVersionID(ctx, ver.ID)
if err != nil {
return nil, errors.Join(tw.Close(), gw.Close(), db.Close(), err)
return nil, err
}
var pf *packages_model.PackageFile
for _, file := range files {
@ -215,7 +218,7 @@ func createDB(ctx context.Context, ownerID int64, group, arch string) (*packages
ctx, packages_model.PropertyTypeFile, pf.ID, arch_module.PropertyDescription,
)
if err != nil {
return nil, errors.Join(tw.Close(), gw.Close(), db.Close(), err)
return nil, err
}
if len(pps) >= 1 {
meta := []byte(pps[0].Value)
@ -225,20 +228,18 @@ func createDB(ctx context.Context, ownerID int64, group, arch string) (*packages
Mode: int64(os.ModePerm),
}
if err = tw.WriteHeader(header); err != nil {
return nil, errors.Join(tw.Close(), gw.Close(), db.Close(), err)
return nil, err
}
if _, err := tw.Write(meta); err != nil {
return nil, errors.Join(tw.Close(), gw.Close(), db.Close(), err)
return nil, err
}
count++
break
}
}
}
defer gw.Close()
defer tw.Close()
if count == 0 {
return nil, errors.Join(db.Close(), io.EOF)
return nil, io.EOF
}
return db, nil
}

@ -332,6 +332,9 @@ func getProperty(data, key string) string {
func listTarGzFiles(data []byte) (fstest.MapFS, error) {
reader, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, err
}
defer reader.Close()
if err != nil {
return nil, err

Loading…
Cancel
Save