mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
refactoring in metadata module, better readability
shorter function calls in arch service fix - request now ends if unable to decode package signature from hex fix - now package search continues to previous versions in package file for required architecture not found for current version
This commit is contained in:
parent
4bf84c1fd6
commit
8974d27ba3
@ -104,18 +104,6 @@ func EjectMetadata(p *EjectParams) (*DbDesc, error) {
|
|||||||
md.URL = value
|
md.URL = value
|
||||||
case "packager":
|
case "packager":
|
||||||
md.Packager = value
|
md.Packager = value
|
||||||
case "builddate":
|
|
||||||
num, err := strconv.ParseInt(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
md.BuildDate = num
|
|
||||||
case "size":
|
|
||||||
num, err := strconv.ParseInt(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
md.InstalledSize = num
|
|
||||||
case "provides":
|
case "provides":
|
||||||
md.Provides = append(md.Provides, value)
|
md.Provides = append(md.Provides, value)
|
||||||
case "license":
|
case "license":
|
||||||
@ -132,6 +120,16 @@ func EjectMetadata(p *EjectParams) (*DbDesc, error) {
|
|||||||
md.CheckDepends = append(md.CheckDepends, value)
|
md.CheckDepends = append(md.CheckDepends, value)
|
||||||
case "backup":
|
case "backup":
|
||||||
md.Backup = append(md.Backup, value)
|
md.Backup = append(md.Backup, value)
|
||||||
|
case "builddate":
|
||||||
|
md.BuildDate, err = strconv.ParseInt(value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
case "size":
|
||||||
|
md.InstalledSize, err = strconv.ParseInt(value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,53 +162,38 @@ func getPkginfo(data io.Reader) (string, error) {
|
|||||||
|
|
||||||
// Create pacman package description file.
|
// Create pacman package description file.
|
||||||
func (m *DbDesc) String() string {
|
func (m *DbDesc) String() string {
|
||||||
return strings.Join(rmEmptyStrings([]string{
|
var entries = []struct {
|
||||||
formatField("FILENAME", m.Filename),
|
Key string
|
||||||
formatField("NAME", m.Name),
|
Value string
|
||||||
formatField("BASE", m.Base),
|
}{
|
||||||
formatField("VERSION", m.Version),
|
{Key: "FILENAME", Value: m.Filename},
|
||||||
formatField("DESC", m.Description),
|
{Key: "NAME", Value: m.Name},
|
||||||
formatField("CSIZE", m.CompressedSize),
|
{Key: "BASE", Value: m.Base},
|
||||||
formatField("ISIZE", m.InstalledSize),
|
{Key: "VERSION", Value: m.Version},
|
||||||
formatField("MD5SUM", m.MD5),
|
{Key: "DESC", Value: m.Description},
|
||||||
formatField("SHA256SUM", m.SHA256),
|
{Key: "CSIZE", Value: fmt.Sprintf("%d", m.CompressedSize)},
|
||||||
formatField("URL", m.URL),
|
{Key: "ISIZE", Value: fmt.Sprintf("%d", m.InstalledSize)},
|
||||||
formatField("LICENSE", m.License),
|
{Key: "MD5SUM", Value: m.MD5},
|
||||||
formatField("ARCH", m.Arch),
|
{Key: "SHA256SUM", Value: m.SHA256},
|
||||||
formatField("BUILDDATE", m.BuildDate),
|
{Key: "URL", Value: m.URL},
|
||||||
formatField("PACKAGER", m.Packager),
|
{Key: "LICENSE", Value: strings.Join(m.License, "\n")},
|
||||||
formatField("PROVIDES", m.Provides),
|
{Key: "ARCH", Value: strings.Join(m.Arch, "\n")},
|
||||||
formatField("DEPENDS", m.Depends),
|
{Key: "BUILDDATE", Value: fmt.Sprintf("%d", m.BuildDate)},
|
||||||
formatField("OPTDEPENDS", m.OptDepends),
|
{Key: "PACKAGER", Value: m.Packager},
|
||||||
formatField("MAKEDEPENDS", m.MakeDepends),
|
{Key: "PROVIDES", Value: strings.Join(m.Provides, "\n")},
|
||||||
formatField("CHECKDEPENDS", m.CheckDepends),
|
{Key: "DEPENDS", Value: strings.Join(m.Depends, "\n")},
|
||||||
}), "\n\n") + "\n\n"
|
{Key: "OPTDEPENDS", Value: strings.Join(m.OptDepends, "\n")},
|
||||||
}
|
{Key: "MAKEDEPENDS", Value: strings.Join(m.MakeDepends, "\n")},
|
||||||
|
{Key: "CHECKDEPENDS", Value: strings.Join(m.CheckDepends, "\n")},
|
||||||
func formatField(field string, value any) string {
|
|
||||||
switch value := value.(type) {
|
|
||||||
case []string:
|
|
||||||
if value == nil {
|
|
||||||
return ``
|
|
||||||
}
|
|
||||||
val := strings.Join(value, "\n")
|
|
||||||
return fmt.Sprintf("%%%s%%\n%s", field, val)
|
|
||||||
case string:
|
|
||||||
return fmt.Sprintf("%%%s%%\n%s", field, value)
|
|
||||||
case int64:
|
|
||||||
return fmt.Sprintf("%%%s%%\n%d", field, value)
|
|
||||||
}
|
}
|
||||||
return ``
|
|
||||||
}
|
|
||||||
|
|
||||||
func rmEmptyStrings(s []string) []string {
|
var result string
|
||||||
var r []string
|
for _, v := range entries {
|
||||||
for _, str := range s {
|
if v.Value != "" {
|
||||||
if str != "" {
|
result += fmt.Sprintf("%%%s%%\n%s\n\n", v.Key, v.Value)
|
||||||
r = append(r, str)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create pacman database archive based on provided package metadata structs.
|
// Create pacman database archive based on provided package metadata structs.
|
||||||
|
@ -59,14 +59,15 @@ func Push(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
props := map[string]string{
|
props := map[string]string{
|
||||||
distro + "-" + filename + ".desc": desc.String(),
|
"desc": desc.String(),
|
||||||
}
|
}
|
||||||
if sign != "" {
|
if sign != "" {
|
||||||
_, err := hex.DecodeString(sign)
|
_, err := hex.DecodeString(sign)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusBadRequest, err)
|
apiError(ctx, http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
props[distro+"-"+filename+".sig"] = sign
|
props["sign"] = sign
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = pkg_service.CreatePackageOrAddFileToExisting(
|
_, _, err = pkg_service.CreatePackageOrAddFileToExisting(
|
||||||
|
@ -44,7 +44,7 @@ func GetPackageSignature(ctx *context.Context, distro, file string) (*bytes.Read
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pp := range proprs {
|
for _, pp := range proprs {
|
||||||
if pp.Name == distro+"-"+file {
|
if pp.Name == "sign" {
|
||||||
b, err := hex.DecodeString(pp.Value)
|
b, err := hex.DecodeString(pp.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -62,7 +62,6 @@ func getPackageFile(ctx *context.Context, distro, file string) (*pkg_model.Packa
|
|||||||
splt = strings.Split(file, "-")
|
splt = strings.Split(file, "-")
|
||||||
pkgname = strings.Join(splt[0:len(splt)-3], "-")
|
pkgname = strings.Join(splt[0:len(splt)-3], "-")
|
||||||
vername = splt[len(splt)-3] + "-" + splt[len(splt)-2]
|
vername = splt[len(splt)-3] + "-" + splt[len(splt)-2]
|
||||||
compkey = distro + "-" + file
|
|
||||||
)
|
)
|
||||||
|
|
||||||
version, err := pkg_model.GetVersionByNameAndVersion(
|
version, err := pkg_model.GetVersionByNameAndVersion(
|
||||||
@ -72,9 +71,7 @@ func getPackageFile(ctx *context.Context, distro, file string) (*pkg_model.Packa
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgfile, err := pkg_model.GetFileForVersionByName(
|
pkgfile, err := pkg_model.GetFileForVersionByName(ctx, version.ID, file, distro)
|
||||||
ctx, version.ID, file, compkey,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -106,36 +103,26 @@ func CreatePacmanDb(ctx *context.Context, owner, arch, distro string) (io.ReadSe
|
|||||||
return versions[i].CreatedUnix > versions[j].CreatedUnix
|
return versions[i].CreatedUnix > versions[j].CreatedUnix
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, version := range versions {
|
for _, ver := range versions {
|
||||||
filename := fmt.Sprintf(
|
file := fmt.Sprintf("%s-%s-%s.pkg.tar.zst", pkg.Name, ver.Version, arch)
|
||||||
"%s-%s-%s.pkg.tar.zst",
|
|
||||||
pkg.Name, version.Version, arch,
|
|
||||||
)
|
|
||||||
|
|
||||||
file, err := pkg_model.GetFileForVersionByName(
|
pf, err := pkg_model.GetFileForVersionByName(ctx, ver.ID, file, distro)
|
||||||
ctx, version.ID, filename, distro+"-"+filename,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
filename := fmt.Sprintf(
|
file = fmt.Sprintf("%s-%s-any.pkg.tar.zst", pkg.Name, ver.Version)
|
||||||
"%s-%s-any.pkg.tar.zst",
|
pf, err = pkg_model.GetFileForVersionByName(ctx, ver.ID, file, distro)
|
||||||
pkg.Name, version.Version,
|
|
||||||
)
|
|
||||||
file, err = pkg_model.GetFileForVersionByName(
|
|
||||||
ctx, version.ID, filename, distro+"-"+filename,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pps, err := pkg_model.GetProperties(ctx, pkg_model.PropertyTypeFile, file.ID)
|
pps, err := pkg_model.GetProperties(ctx, pkg_model.PropertyTypeFile, pf.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var descvalue string
|
var descvalue string
|
||||||
for _, pp := range pps {
|
for _, pp := range pps {
|
||||||
if strings.HasSuffix(pp.Name, ".desc") {
|
if pp.Name == "desc" {
|
||||||
descvalue = pp.Value
|
descvalue = pp.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +131,7 @@ func CreatePacmanDb(ctx *context.Context, owner, arch, distro string) (io.ReadSe
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
entries[pkg.Name+"-"+version.Version+"/desc"] = []byte(descvalue)
|
entries[pkg.Name+"-"+ver.Version+"/desc"] = []byte(descvalue)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user