Skip to content

Commit 49e8fbe

Browse files
committed
fix
1 parent 6279646 commit 49e8fbe

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

services/repository/avatar.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"io"
1010
"strconv"
11-
"strings"
1211

1312
"code.gitea.io/gitea/models/db"
1413
repo_model "code.gitea.io/gitea/models/repo"
@@ -107,7 +106,8 @@ func RemoveRandomAvatars(ctx context.Context) error {
107106

108107
// generateAvatar generates the avatar from a template repository
109108
func generateAvatar(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
110-
generateRepo.Avatar = strings.Replace(templateRepo.Avatar, strconv.FormatInt(templateRepo.ID, 10), strconv.FormatInt(generateRepo.ID, 10), 1)
109+
// generate a new different hash, whatever the "hash data" is, it doesn't matter
110+
generateRepo.Avatar = avatar.HashAvatar(generateRepo.ID, []byte("new-avatar"))
111111
if _, err := storage.Copy(storage.RepoAvatars, generateRepo.CustomAvatarRelativePath(), storage.RepoAvatars, templateRepo.CustomAvatarRelativePath()); err != nil {
112112
return err
113113
}

services/repository/avatar_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ func TestDeleteAvatar(t *testing.T) {
6161

6262
assert.Equal(t, "", repo.Avatar)
6363
}
64+
65+
func TestGenerateAvatar(t *testing.T) {
66+
templateRepo := &repo_model.Repository{ID: 10, Avatar: "a"}
67+
generateRepo := &repo_model.Repository{ID: 11}
68+
_ = generateAvatar(db.DefaultContext, templateRepo, generateRepo)
69+
assert.NotEmpty(t, generateRepo.Avatar)
70+
assert.NotEqual(t, templateRepo.Avatar, generateRepo.Avatar)
71+
}

services/repository/delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, repoID
317317

318318
if len(repo.Avatar) > 0 {
319319
if err := storage.RepoAvatars.Delete(repo.CustomAvatarRelativePath()); err != nil {
320-
return fmt.Errorf("Failed to remove %s: %w", repo.Avatar, err)
320+
log.Error("remove avatar file %q: %v", repo.CustomAvatarRelativePath(), err)
321+
// go on
321322
}
322323
}
323324

0 commit comments

Comments
 (0)