diff --git a/modules/repository/license_test.go b/modules/repository/license_test.go index 3b0cfa1eed..d00156a496 100644 --- a/modules/repository/license_test.go +++ b/modules/repository/license_test.go @@ -31,12 +31,7 @@ func Test_getLicense(t *testing.T) { Copyright (c) 2023 Gitea -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -`, +Permission is hereby granted`, wantErr: assert.NoError, }, { @@ -53,7 +48,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI if !tt.wantErr(t, err, fmt.Sprintf("GetLicense(%v, %v)", tt.args.name, tt.args.values)) { return } - assert.Equalf(t, tt.want, string(got), "GetLicense(%v, %v)", tt.args.name, tt.args.values) + assert.Contains(t, string(got), tt.want, "GetLicense(%v, %v)", tt.args.name, tt.args.values) }) } } diff --git a/services/repository/avatar.go b/services/repository/avatar.go index 38c2621bc4..15e51d4a25 100644 --- a/services/repository/avatar.go +++ b/services/repository/avatar.go @@ -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 } diff --git a/services/repository/avatar_test.go b/services/repository/avatar_test.go index 4a0ba61853..bea820e85f 100644 --- a/services/repository/avatar_test.go +++ b/services/repository/avatar_test.go @@ -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) +} diff --git a/services/repository/delete.go b/services/repository/delete.go index f33bae7790..aa1bbf884c 100644 --- a/services/repository/delete.go +++ b/services/repository/delete.go @@ -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 } }