aboutsummaryrefslogtreecommitdiffstats
path: root/models/user
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-11-15 08:08:59 +0000
committerGitHub <noreply@github.com>2022-11-15 16:08:59 +0800
commitc772934ff623b3a76efbe306f597695330a71287 (patch)
tree4639644b2bcc0e8ee3573283c8c7190a80b24a59 /models/user
parentde6dfb714153c17a06406c866805a17a476c63bd (diff)
downloadgitea-c772934ff623b3a76efbe306f597695330a71287.tar.gz
gitea-c772934ff623b3a76efbe306f597695330a71287.zip
Adjust gitea doctor --run storages to check all storage types (#21785)
The doctor check `storages` currently only checks the attachment storage. This PR adds some basic garbage collection functionality for the other types of storage. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/user')
-rw-r--r--models/user/avatar.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/models/user/avatar.go b/models/user/avatar.go
index 102206f3a2..f523766746 100644
--- a/models/user/avatar.go
+++ b/models/user/avatar.go
@@ -111,3 +111,10 @@ func (u *User) IsUploadAvatarChanged(data []byte) bool {
avatarID := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
return u.Avatar != avatarID
}
+
+// ExistsWithAvatarAtStoragePath returns true if there is a user with this Avatar
+func ExistsWithAvatarAtStoragePath(ctx context.Context, storagePath string) (bool, error) {
+ // See func (u *User) CustomAvatarRelativePath()
+ // u.Avatar is used directly as the storage path - therefore we can check for existence directly using the path
+ return db.GetEngine(ctx).Where("`avatar`=?", storagePath).Exist(new(User))
+}