@@ -8,13 +8,10 @@ import (
88 "errors"
99 "fmt"
1010 "net/url"
11- "os"
1211 "path"
1312
1413 "code.gitea.io/gitea/models/db"
15- "code.gitea.io/gitea/modules/log"
1614 "code.gitea.io/gitea/modules/setting"
17- "code.gitea.io/gitea/modules/storage"
1815 "code.gitea.io/gitea/modules/timeutil"
1916 "code.gitea.io/gitea/modules/util"
2017)
@@ -166,61 +163,6 @@ func GetAttachmentByReleaseIDFileName(ctx context.Context, releaseID int64, file
166163 return attach , nil
167164}
168165
169- // DeleteAttachment deletes the given attachment and optionally the associated file.
170- func DeleteAttachment (ctx context.Context , a * Attachment , remove bool ) error {
171- _ , err := DeleteAttachments (ctx , []* Attachment {a }, remove )
172- return err
173- }
174-
175- // DeleteAttachments deletes the given attachments and optionally the associated files.
176- func DeleteAttachments (ctx context.Context , attachments []* Attachment , remove bool ) (int , error ) {
177- if len (attachments ) == 0 {
178- return 0 , nil
179- }
180-
181- ids := make ([]int64 , 0 , len (attachments ))
182- for _ , a := range attachments {
183- ids = append (ids , a .ID )
184- }
185-
186- cnt , err := db .GetEngine (ctx ).In ("id" , ids ).NoAutoCondition ().Delete (attachments [0 ])
187- if err != nil {
188- return 0 , err
189- }
190-
191- if remove {
192- for i , a := range attachments {
193- if err := storage .Attachments .Delete (a .RelativePath ()); err != nil {
194- if ! errors .Is (err , os .ErrNotExist ) {
195- return i , err
196- }
197- log .Warn ("Attachment file not found when deleting: %s" , a .RelativePath ())
198- }
199- }
200- }
201- return int (cnt ), nil
202- }
203-
204- // DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
205- func DeleteAttachmentsByIssue (ctx context.Context , issueID int64 , remove bool ) (int , error ) {
206- attachments , err := GetAttachmentsByIssueID (ctx , issueID )
207- if err != nil {
208- return 0 , err
209- }
210-
211- return DeleteAttachments (ctx , attachments , remove )
212- }
213-
214- // DeleteAttachmentsByComment deletes all attachments associated with the given comment.
215- func DeleteAttachmentsByComment (ctx context.Context , commentID int64 , remove bool ) (int , error ) {
216- attachments , err := GetAttachmentsByCommentID (ctx , commentID )
217- if err != nil {
218- return 0 , err
219- }
220-
221- return DeleteAttachments (ctx , attachments , remove )
222- }
223-
224166// UpdateAttachmentByUUID Updates attachment via uuid
225167func UpdateAttachmentByUUID (ctx context.Context , attach * Attachment , cols ... string ) error {
226168 if attach .UUID == "" {
0 commit comments