@@ -14,6 +14,7 @@ import (
14
14
15
15
"code.gitea.io/gitea/models/db"
16
16
user_model "code.gitea.io/gitea/models/user"
17
+ "code.gitea.io/gitea/modules/container"
17
18
"code.gitea.io/gitea/modules/structs"
18
19
"code.gitea.io/gitea/modules/timeutil"
19
20
"code.gitea.io/gitea/modules/util"
@@ -336,6 +337,17 @@ func (s releaseMetaSearch) Less(i, j int) bool {
336
337
return s .ID [i ] < s .ID [j ]
337
338
}
338
339
340
+ func hasDuplicateName (attaches []* Attachment ) bool {
341
+ attachSet := container.Set [string ]{}
342
+ for _ , attachment := range attaches {
343
+ if attachSet .Contains (attachment .Name ) {
344
+ return true
345
+ }
346
+ attachSet .Add (attachment .Name )
347
+ }
348
+ return false
349
+ }
350
+
339
351
// GetReleaseAttachments retrieves the attachments for releases
340
352
func GetReleaseAttachments (ctx context.Context , rels ... * Release ) (err error ) {
341
353
if len (rels ) == 0 {
@@ -360,7 +372,7 @@ func GetReleaseAttachments(ctx context.Context, rels ...*Release) (err error) {
360
372
err = db .GetEngine (ctx ).
361
373
Asc ("release_id" , "name" ).
362
374
In ("release_id" , sortedRels .ID ).
363
- Find (& attachments , Attachment {} )
375
+ Find (& attachments )
364
376
if err != nil {
365
377
return err
366
378
}
@@ -381,21 +393,8 @@ func GetReleaseAttachments(ctx context.Context, rels ...*Release) (err error) {
381
393
continue
382
394
}
383
395
384
- // Check if there are two or more attachments with the same name
385
- hasDuplicates := false
386
- foundNames := make (map [string ]bool )
387
- for _ , attachment := range release .Attachments {
388
- _ , found := foundNames [attachment .Name ]
389
- if found {
390
- hasDuplicates = true
391
- break
392
- } else {
393
- foundNames [attachment .Name ] = true
394
- }
395
- }
396
-
397
396
// If the names unique, use the URL with the Name instead of the UUID
398
- if ! hasDuplicates {
397
+ if ! hasDuplicateName ( release . Attachments ) {
399
398
for _ , attachment := range release .Attachments {
400
399
attachment .CustomDownloadURL = release .Repo .HTMLURL () + "/releases/download/" + url .PathEscape (release .TagName ) + "/" + url .PathEscape (attachment .Name )
401
400
}
0 commit comments