mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09: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>
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package packages
|
|
|
|
import (
|
|
"context"
|
|
"html/template"
|
|
"sync"
|
|
|
|
packages_model "gitea.dev/models/packages"
|
|
user_model "gitea.dev/models/user"
|
|
)
|
|
|
|
type SpecGetViewPackageVersionData struct{}
|
|
|
|
func (*SpecGetViewPackageVersionData) GetViewPackageVersionData(ctx context.Context, pd *packages_model.PackageDescriptor) (any, error) {
|
|
return nil, nil //nolint:nilnil // no data, no error
|
|
}
|
|
|
|
type SpecOnBeforeRemovePackageAll struct{}
|
|
|
|
func (*SpecOnBeforeRemovePackageAll) OnBeforeRemovePackageAll(ctx context.Context, doer *user_model.User, pkg *packages_model.Package, pds []*packages_model.PackageDescriptor) error {
|
|
return nil
|
|
}
|
|
|
|
type SpecOnBeforeRemovePackageVersion struct{}
|
|
|
|
func (*SpecOnBeforeRemovePackageVersion) OnBeforeRemovePackageVersion(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) error {
|
|
return nil
|
|
}
|
|
|
|
type SpecOnAfterRemovePackage struct{}
|
|
|
|
func (*SpecOnAfterRemovePackage) OnAfterRemovePackage(ctx context.Context, pkg *packages_model.Package) error {
|
|
return nil
|
|
}
|
|
|
|
type SpecRenderUsageManual struct{}
|
|
|
|
func (*SpecRenderUsageManual) RenderSetupManual(ctx context.Context, pkg *packages_model.PackageDescriptor, viewData any) template.HTML {
|
|
return ""
|
|
}
|
|
|
|
type SpecPublicPropertyNames struct{}
|
|
|
|
func (*SpecPublicPropertyNames) PublicPropertyNames() []string {
|
|
return nil
|
|
}
|
|
|
|
type specDefault struct {
|
|
SpecPublicPropertyNames
|
|
SpecGetViewPackageVersionData
|
|
SpecOnBeforeRemovePackageAll
|
|
SpecOnBeforeRemovePackageVersion
|
|
SpecOnAfterRemovePackage
|
|
SpecRenderUsageManual
|
|
}
|
|
|
|
func (n *specDefault) OnBeforeRemovePackageVersion(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) error {
|
|
return nil
|
|
}
|
|
|
|
var _ Specialization = (*specDefault)(nil)
|
|
|
|
type SpecManagerType struct {
|
|
specMap map[packages_model.Type]Specialization
|
|
}
|
|
|
|
func (m *SpecManagerType) Add(t packages_model.Type, spec Specialization) {
|
|
m.specMap[t] = spec
|
|
}
|
|
|
|
func (m *SpecManagerType) Get(t packages_model.Type) Specialization {
|
|
if len(m.specMap) == 0 {
|
|
panic("specialization not initialized")
|
|
}
|
|
spec := m.specMap[t]
|
|
if spec == nil {
|
|
return &specDefault{}
|
|
}
|
|
return spec
|
|
}
|
|
|
|
var GetSpecManager = sync.OnceValue(func() *SpecManagerType {
|
|
return &SpecManagerType{specMap: make(map[packages_model.Type]Specialization)}
|
|
})
|