diff --git a/integrations/attachment_test.go b/integrations/attachment_test.go index 3dfc4faca..533725a2a 100644 --- a/integrations/attachment_test.go +++ b/integrations/attachment_test.go @@ -14,6 +14,7 @@ import ( "strings" "testing" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/test" @@ -121,7 +122,7 @@ func TestGetAttachment(t *testing.T) { t.Run(tc.name, func(t *testing.T) { //Write empty file to be available for response if tc.createFile { - err = storage.Attachments.Save(tc.RelativePath(), strings.NewReader("hello world")) + _, err := storage.Attachments.Save(models.AttachmentRelativePath(tc), strings.NewReader("hello world")) assert.NoError(t, err) } //Actual test diff --git a/models/attachment.go b/models/attachment.go index 4a1cea541..b2a2c42ea 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -61,9 +61,14 @@ func (a *Attachment) DownloadURL() string { return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID) } +// AttachmentRelativePath returns the relative path +func AttachmentRelativePath(uuid string) string { + return path.Join(uuid[0:1], uuid[1:2], uuid) +} + // RelativePath returns the relative path of the attachment func (a *Attachment) RelativePath() string { - return path.Join(a.UUID[0:1], a.UUID[1:2], a.UUID) + return AttachmentRelativePath(a.UUID) } // LinkedRepository returns the linked repo if any @@ -288,4 +293,4 @@ func IterateAttachment(f func(attach *Attachment) error) error { } } } -} \ No newline at end of file +}