mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-23 08:24:37 +00:00
Deleting a package or a package version from the web UI, the admin panel or `DELETE /api/v1/packages/...` removed the database rows but never rebuilt the Debian, Alpine, RPM or Arch repository index, so clients kept seeing the deleted version until something else triggered a rebuild. Only the registries' own delete endpoints and the cleanup task rebuilt it. https://github.com/go-gitea/gitea/pull/22810 was closed in favor of `OnBeforeRemovePackageVersion`, but that hook runs before the version is gone, so it can't refresh the index. This adds an `OnAfterRemovePackage` hook and rebuilds the owner's repository files there, the same way the cleanup task does. Deleting the last RPM of a group also removed the repodata of all other groups of the owner. Now only the emptied group's files are removed. Fixes: https://github.com/go-gitea/gitea/issues/32830 Fixes: https://github.com/go-gitea/gitea/issues/40304 Fixes: https://github.com/go-gitea/gitea/issues/40305 --- 🤖 Opened with [Superhuman](https://github.com/gaurav0107/superhuman), an open-source contribution agent. --------- Co-authored-by: silverwind <me@silverwind.io>
96 lines
3.3 KiB
Go
96 lines
3.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package debian
|
|
|
|
import (
|
|
"context"
|
|
"html/template"
|
|
"strings"
|
|
|
|
packages_model "gitea.dev/models/packages"
|
|
"gitea.dev/modules/container"
|
|
"gitea.dev/modules/htmlutil"
|
|
"gitea.dev/modules/httplib"
|
|
debian_module "gitea.dev/modules/packages/debian"
|
|
"gitea.dev/modules/util"
|
|
packages_service "gitea.dev/services/packages"
|
|
)
|
|
|
|
type Specialization struct {
|
|
packages_service.SpecOnBeforeRemovePackageAll
|
|
packages_service.SpecOnBeforeRemovePackageVersion
|
|
}
|
|
|
|
var _ packages_service.Specialization = (*Specialization)(nil)
|
|
|
|
func (s Specialization) OnAfterRemovePackage(ctx context.Context, pkg *packages_model.Package) error {
|
|
return BuildAllRepositoryFiles(ctx, pkg.OwnerID)
|
|
}
|
|
|
|
type debianViewData struct {
|
|
Distributions []string
|
|
Components []string
|
|
Architectures []string
|
|
}
|
|
|
|
func (s Specialization) GetViewPackageVersionData(ctx context.Context, pd *packages_model.PackageDescriptor) (any, error) {
|
|
distributions := make(container.Set[string])
|
|
components := make(container.Set[string])
|
|
architectures := make(container.Set[string])
|
|
for _, f := range pd.Files {
|
|
for _, pp := range f.Properties {
|
|
switch pp.Name {
|
|
case debian_module.PropertyDistribution:
|
|
distributions.Add(pp.Value)
|
|
case debian_module.PropertyComponent:
|
|
components.Add(pp.Value)
|
|
case debian_module.PropertyArchitecture:
|
|
architectures.Add(pp.Value)
|
|
}
|
|
}
|
|
}
|
|
viewData := debianViewData{
|
|
Distributions: util.Sorted(distributions.Values()),
|
|
Components: util.Sorted(components.Values()),
|
|
Architectures: util.Sorted(architectures.Values()),
|
|
}
|
|
return viewData, nil
|
|
}
|
|
|
|
func writeVarSelect(w *htmlutil.HTMLBuilder, varName string, varItems []string) {
|
|
w.WriteFormatf(`<div>%s=<select data-code-var="%s">`, varName, varName)
|
|
for _, v := range varItems {
|
|
w.WriteFormatf(`<option value="%s">%s</option>`, v, v)
|
|
}
|
|
w.WriteHTML("</select></div>")
|
|
}
|
|
|
|
func (s Specialization) RenderSetupManual(ctx context.Context, pkg *packages_model.PackageDescriptor, viewDataAny any) template.HTML {
|
|
viewData := viewDataAny.(debianViewData) //nolint:forcetypeassert // must be valid
|
|
const nl = "\n"
|
|
appFullLink := strings.TrimSuffix(httplib.GuessCurrentAppURL(ctx), "/")
|
|
|
|
w := &htmlutil.HTMLBuilder{}
|
|
w.WriteHTML(`<div data-global-init="initPackagesManualVars">`)
|
|
{
|
|
w.WriteHTML(`<div class="package-manual-vars">`)
|
|
writeVarSelect(w, "distribution", viewData.Distributions)
|
|
writeVarSelect(w, "component", viewData.Components)
|
|
w.WriteHTML(`</div>`)
|
|
}
|
|
{
|
|
w.WriteHTML(`<div class="markup"><pre class="code-block"><code>`)
|
|
w.WriteFormatf(`sudo curl %s/api/packages/%s/debian/repository.key -o /etc/apt/keyrings/gitea-%s.asc`+nl+nl, appFullLink, pkg.Owner.Name, pkg.Owner.Name)
|
|
w.WriteFormatf(`echo "deb [signed-by=/etc/apt/keyrings/gitea-%s.asc] %s/api/packages/%s/debian <span>$distribution</span> <span>$component</span>" | sudo tee -a /etc/apt/sources.list.d/gitea.list`+nl+nl, pkg.Owner.Name, appFullLink, pkg.Owner.Name)
|
|
w.WriteHTML(`sudo apt update` + nl)
|
|
w.WriteHTML(`</code></pre></div>`)
|
|
}
|
|
w.WriteHTML(`</div>`)
|
|
return w.HTMLString()
|
|
}
|
|
|
|
func (s Specialization) PublicPropertyNames() []string {
|
|
return []string{debian_module.PropertyDistribution, debian_module.PropertyComponent, debian_module.PropertyArchitecture}
|
|
}
|