diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-09-03 18:01:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-03 17:01:00 +0100 |
commit | 5bc73ca666588ac26cc7cea219866b79c5263527 (patch) | |
tree | 85fed3af6d25077b3d4b854e86520c6c92155396 /models/packages/package.go | |
parent | 1670109b91a6d5cfb4da0225d7a52c423031322d (diff) | |
download | gitea-5bc73ca666588ac26cc7cea219866b79c5263527.tar.gz gitea-5bc73ca666588ac26cc7cea219866b79c5263527.zip |
Delete unreferenced packages when deleting a package version (#20977)
Delete a package if its last version got deleted. Otherwise removing the owner works only after the clean up job ran.
Fix #20969
Diffstat (limited to 'models/packages/package.go')
-rw-r--r-- | models/packages/package.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/models/packages/package.go b/models/packages/package.go index c203901a2d..e39a7c4e41 100644 --- a/models/packages/package.go +++ b/models/packages/package.go @@ -224,9 +224,16 @@ func FindUnreferencedPackages(ctx context.Context) ([]*Package, error) { Find(&ps) } -// HasOwnerPackages tests if a user/org has packages +// HasOwnerPackages tests if a user/org has accessible packages func HasOwnerPackages(ctx context.Context, ownerID int64) (bool, error) { - return db.GetEngine(ctx).Where("owner_id = ?", ownerID).Exist(&Package{}) + return db.GetEngine(ctx). + Table("package_version"). + Join("INNER", "package", "package.id = package_version.package_id"). + Where(builder.Eq{ + "package_version.is_internal": false, + "package.owner_id": ownerID, + }). + Exist(&PackageVersion{}) } // HasRepositoryPackages tests if a repository has packages |