aboutsummaryrefslogtreecommitdiffstats
path: root/services/packages
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-04-06 03:32:09 +0200
committerGitHub <noreply@github.com>2022-04-06 03:32:09 +0200
commit5e242e021b9f32d2d136e4f3324cb56be415f484 (patch)
tree01bde0162b15ecb069d13d53413dfbb5d514a945 /services/packages
parent8ddcd37f13411f38a7e4bbd1c1f931436af255b6 (diff)
downloadgitea-5e242e021b9f32d2d136e4f3324cb56be415f484.tar.gz
gitea-5e242e021b9f32d2d136e4f3324cb56be415f484.zip
Package registry changes (#19305)
* removed debug logs * fixed SELECT * removed unneeded error type * use common SearchVersions method * remove empty container upload versions * return err
Diffstat (limited to 'services/packages')
-rw-r--r--services/packages/container/cleanup.go31
-rw-r--r--services/packages/packages.go11
2 files changed, 21 insertions, 21 deletions
diff --git a/services/packages/container/cleanup.go b/services/packages/container/cleanup.go
index 91992a4d7f..390a0b7b05 100644
--- a/services/packages/container/cleanup.go
+++ b/services/packages/container/cleanup.go
@@ -10,6 +10,7 @@ import (
packages_model "code.gitea.io/gitea/models/packages"
container_model "code.gitea.io/gitea/models/packages/container"
+ "code.gitea.io/gitea/modules/util"
)
// Cleanup removes expired container data
@@ -43,10 +44,7 @@ func cleanupExpiredUploadedBlobs(ctx context.Context, olderThan time.Duration) e
return err
}
- versions := make(map[int64]struct{})
for _, pf := range pfs {
- versions[pf.VersionID] = struct{}{}
-
if err := packages_model.DeleteAllProperties(ctx, packages_model.PropertyTypeFile, pf.ID); err != nil {
return err
}
@@ -55,19 +53,26 @@ func cleanupExpiredUploadedBlobs(ctx context.Context, olderThan time.Duration) e
}
}
- for versionID := range versions {
- has, err := packages_model.HasVersionFileReferences(ctx, versionID)
- if err != nil {
+ pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
+ Type: packages_model.TypeContainer,
+ Version: packages_model.SearchValue{
+ ExactMatch: true,
+ Value: container_model.UploadVersion,
+ },
+ IsInternal: true,
+ HasFiles: util.OptionalBoolFalse,
+ })
+ if err != nil {
+ return err
+ }
+
+ for _, pv := range pvs {
+ if err := packages_model.DeleteAllProperties(ctx, packages_model.PropertyTypeVersion, pv.ID); err != nil {
return err
}
- if !has {
- if err := packages_model.DeleteAllProperties(ctx, packages_model.PropertyTypeVersion, versionID); err != nil {
- return err
- }
- if err := packages_model.DeleteVersionByID(ctx, versionID); err != nil {
- return err
- }
+ if err := packages_model.DeleteVersionByID(ctx, pv.ID); err != nil {
+ return err
}
}
diff --git a/services/packages/packages.go b/services/packages/packages.go
index 7f90f80baf..7f25fce5b8 100644
--- a/services/packages/packages.go
+++ b/services/packages/packages.go
@@ -336,7 +336,7 @@ func DeletePackageFile(ctx context.Context, pf *packages_model.PackageFile) erro
return packages_model.DeleteFileByID(ctx, pf.ID)
}
-// Cleanup removes old unreferenced package blobs
+// Cleanup removes expired package data
func Cleanup(unused context.Context, olderThan time.Duration) error {
ctx, committer, err := db.TxContext()
if err != nil {
@@ -345,24 +345,20 @@ func Cleanup(unused context.Context, olderThan time.Duration) error {
defer committer.Close()
if err := container_service.Cleanup(ctx, olderThan); err != nil {
- log.Error("hier")
return err
}
if err := packages_model.DeletePackagesIfUnreferenced(ctx); err != nil {
- log.Error("hier2")
return err
}
pbs, err := packages_model.FindExpiredUnreferencedBlobs(ctx, olderThan)
if err != nil {
- log.Error("hier3")
return err
}
for _, pb := range pbs {
if err := packages_model.DeleteBlobByID(ctx, pb.ID); err != nil {
- log.Error("hier4")
return err
}
}
@@ -403,10 +399,9 @@ func GetFileStreamByPackageVersionAndFileID(ctx context.Context, owner *user_mod
pv, err := packages_model.GetVersionByID(ctx, versionID)
if err != nil {
- if err == packages_model.ErrPackageVersionNotExist {
- return nil, nil, packages_model.ErrPackageNotExist
+ if err != packages_model.ErrPackageNotExist {
+ log.Error("Error getting package version: %v", err)
}
- log.Error("Error getting package version: %v", err)
return nil, nil, err
}