feat: vendor gitea 1.16.2
This commit is contained in:
@@ -9,7 +9,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
@@ -57,7 +59,7 @@ func GetRepositoryKey(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.ServeContent(strings.NewReader(pub), &context.ServeHeaderOptions{
|
||||
ctx.ServeContent(strings.NewReader(pub), context.ServeHeaderOptions{
|
||||
ContentType: "application/pgp-keys",
|
||||
Filename: "repository.key",
|
||||
})
|
||||
@@ -80,7 +82,7 @@ func CheckRepositoryFileExistence(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetServeHeaders(&context.ServeHeaderOptions{
|
||||
ctx.SetServeHeaders(context.ServeHeaderOptions{
|
||||
Filename: pf.Name,
|
||||
LastModified: pf.CreatedUnix.AsLocalTime(),
|
||||
})
|
||||
@@ -219,30 +221,38 @@ func UploadPackageFile(ctx *context.Context) {
|
||||
func DownloadPackageFile(ctx *context.Context) {
|
||||
name := ctx.PathParam("name")
|
||||
version := ctx.PathParam("version")
|
||||
architecture := ctx.PathParam("architecture")
|
||||
group := ctx.PathParam("group")
|
||||
|
||||
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
|
||||
ctx,
|
||||
&packages_service.PackageInfo{
|
||||
Owner: ctx.Package.Owner,
|
||||
PackageType: packages_model.TypeRpm,
|
||||
Name: name,
|
||||
Version: version,
|
||||
},
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: fmt.Sprintf("%s-%s.%s.rpm", name, version, ctx.PathParam("architecture")),
|
||||
CompositeKey: ctx.PathParam("group"),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
} else {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
}
|
||||
return
|
||||
openForDownload := func(filename string) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
|
||||
return packages_service.OpenFileForDownloadByPackageNameAndVersion(
|
||||
ctx,
|
||||
&packages_service.PackageInfo{
|
||||
Owner: ctx.Package.Owner,
|
||||
PackageType: packages_model.TypeRpm,
|
||||
Name: name,
|
||||
Version: version,
|
||||
},
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
CompositeKey: group,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
}
|
||||
|
||||
s, u, pf, err := openForDownload(fmt.Sprintf("%s-%s.%s.rpm", name, version, architecture))
|
||||
if errors.Is(err, util.ErrNotExist) && architecture != "noarch" {
|
||||
s, u, pf, err = openForDownload(fmt.Sprintf("%s-%s.%s.rpm", name, version, "noarch"))
|
||||
}
|
||||
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
return
|
||||
} else if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
helper.ServePackageFile(ctx, s, u, pf)
|
||||
}
|
||||
|
||||
@@ -316,3 +326,146 @@ func DeletePackageFile(webctx *context.Context) {
|
||||
|
||||
webctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// UploadErrata handles uploading errata information for a package version
|
||||
func UploadErrata(ctx *context.Context) {
|
||||
name := ctx.PathParam("name")
|
||||
version := ctx.PathParam("version")
|
||||
group := ctx.PathParam("group")
|
||||
|
||||
var updates []*rpm_module.Update
|
||||
if err := json.NewDecoder(ctx.Req.Body).Decode(&updates); err != nil {
|
||||
apiError(ctx, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx,
|
||||
ctx.Package.Owner.ID,
|
||||
packages_model.TypeRpm,
|
||||
name,
|
||||
version,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
} else {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var vm *rpm_module.VersionMetadata
|
||||
if pv.MetadataJSON != "" {
|
||||
if err := json.Unmarshal([]byte(pv.MetadataJSON), &vm); err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
vm = &rpm_module.VersionMetadata{}
|
||||
}
|
||||
|
||||
now := time.Now().Format("2006-01-02 15:04:05")
|
||||
for _, u := range updates {
|
||||
if u == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Sanitize to remove nil elements from JSON payload
|
||||
var cleanPkgList []*rpm_module.Collection
|
||||
for _, coll := range u.PkgList {
|
||||
if coll == nil {
|
||||
continue
|
||||
}
|
||||
var cleanPackages []*rpm_module.UpdatePackage
|
||||
for _, pkg := range coll.Packages {
|
||||
if pkg == nil {
|
||||
continue
|
||||
}
|
||||
cleanPackages = append(cleanPackages, pkg)
|
||||
}
|
||||
coll.Packages = cleanPackages
|
||||
cleanPkgList = append(cleanPkgList, coll)
|
||||
}
|
||||
u.PkgList = cleanPkgList
|
||||
|
||||
found := false
|
||||
for i, existing := range vm.Updates {
|
||||
if existing.ID == u.ID {
|
||||
// Merge PkgList with deduplication
|
||||
for _, newColl := range u.PkgList {
|
||||
if newColl == nil {
|
||||
continue
|
||||
}
|
||||
collFound := false
|
||||
for j, existingColl := range existing.PkgList {
|
||||
if existingColl.Short == newColl.Short {
|
||||
// Merge packages
|
||||
for _, newPkg := range newColl.Packages {
|
||||
if newPkg == nil {
|
||||
continue
|
||||
}
|
||||
pkgFound := false
|
||||
for _, existingPkg := range existingColl.Packages {
|
||||
if existingPkg.Name == newPkg.Name &&
|
||||
existingPkg.Version == newPkg.Version &&
|
||||
existingPkg.Release == newPkg.Release &&
|
||||
existingPkg.Arch == newPkg.Arch {
|
||||
pkgFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !pkgFound {
|
||||
vm.Updates[i].PkgList[j].Packages = append(vm.Updates[i].PkgList[j].Packages, newPkg)
|
||||
}
|
||||
}
|
||||
collFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !collFound {
|
||||
vm.Updates[i].PkgList = append(vm.Updates[i].PkgList, newColl)
|
||||
}
|
||||
}
|
||||
vm.Updates[i].From = u.From
|
||||
vm.Updates[i].Status = u.Status
|
||||
vm.Updates[i].Type = u.Type
|
||||
vm.Updates[i].Version = u.Version
|
||||
vm.Updates[i].Title = u.Title
|
||||
vm.Updates[i].Severity = u.Severity
|
||||
vm.Updates[i].Description = u.Description
|
||||
vm.Updates[i].References = u.References
|
||||
vm.Updates[i].Updated = &rpm_module.DateAttr{Date: now}
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
if u.Issued == nil {
|
||||
u.Issued = &rpm_module.DateAttr{Date: now}
|
||||
}
|
||||
if u.Updated == nil {
|
||||
u.Updated = &rpm_module.DateAttr{Date: now}
|
||||
}
|
||||
vm.Updates = append(vm.Updates, u)
|
||||
}
|
||||
}
|
||||
|
||||
vmBytes, err := json.Marshal(vm)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
pv.MetadataJSON = string(vmBytes)
|
||||
if err := packages_model.UpdateVersion(ctx, pv); err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := rpm_service.BuildSpecificRepositoryFiles(ctx, ctx.Package.Owner.ID, group); err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user