mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Backport #32958 by wxiaoguang Continue even if the avatar deleting fails Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -107,7 +106,8 @@ func RemoveRandomAvatars(ctx context.Context) error {
|
||||
|
||||
// generateAvatar generates the avatar from a template repository
|
||||
func generateAvatar(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
|
||||
generateRepo.Avatar = strings.Replace(templateRepo.Avatar, strconv.FormatInt(templateRepo.ID, 10), strconv.FormatInt(generateRepo.ID, 10), 1)
|
||||
// generate a new different hash, whatever the "hash data" is, it doesn't matter
|
||||
generateRepo.Avatar = avatar.HashAvatar(generateRepo.ID, []byte("new-avatar"))
|
||||
if _, err := storage.Copy(storage.RepoAvatars, generateRepo.CustomAvatarRelativePath(), storage.RepoAvatars, templateRepo.CustomAvatarRelativePath()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -61,3 +61,11 @@ func TestDeleteAvatar(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "", repo.Avatar)
|
||||
}
|
||||
|
||||
func TestGenerateAvatar(t *testing.T) {
|
||||
templateRepo := &repo_model.Repository{ID: 10, Avatar: "a"}
|
||||
generateRepo := &repo_model.Repository{ID: 11}
|
||||
_ = generateAvatar(db.DefaultContext, templateRepo, generateRepo)
|
||||
assert.NotEmpty(t, generateRepo.Avatar)
|
||||
assert.NotEqual(t, templateRepo.Avatar, generateRepo.Avatar)
|
||||
}
|
||||
|
@@ -324,7 +324,8 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, repoID
|
||||
|
||||
if len(repo.Avatar) > 0 {
|
||||
if err := storage.RepoAvatars.Delete(repo.CustomAvatarRelativePath()); err != nil {
|
||||
return fmt.Errorf("Failed to remove %s: %w", repo.Avatar, err)
|
||||
log.Error("remove avatar file %q: %v", repo.CustomAvatarRelativePath(), err)
|
||||
// go on
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user