Skip to content

Commit 4ac0923

Browse files
committed
delete attachments from the database and file system
1 parent 8b36f01 commit 4ac0923

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

models/release.go

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package models
66

77
import (
88
"fmt"
9+
"os"
910
"sort"
1011
"strings"
1112

@@ -469,6 +470,24 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error {
469470
go HookQueue.Add(rel.Repo.ID)
470471
}
471472

473+
if setting.AttachmentEnabled {
474+
475+
uuids := make([]string, 0, len(rel.Attachments))
476+
477+
for i := range rel.Attachments {
478+
attachment := rel.Attachments[i]
479+
if err := os.RemoveAll(attachment.LocalPath()); err != nil {
480+
return err
481+
}
482+
483+
uuids = append(uuids, attachment.UUID)
484+
}
485+
486+
if _, err := x.In("uuid", uuids).Delete(new(Attachment)); err != nil {
487+
return err
488+
}
489+
}
490+
472491
return nil
473492
}
474493

0 commit comments

Comments
 (0)