summaryrefslogtreecommitdiffstats
path: root/models/release.go
diff options
context:
space:
mode:
authorLanre Adelowo <yo@lanre.wtf>2019-09-22 10:05:48 +0100
committerLauris BH <lauris@nix.lv>2019-09-22 12:05:48 +0300
commit63ff61615ec6aaa25887f8ce605c9082c106a34b (patch)
treec00595b76b52a8a694f93f56fab265bcab5d24a6 /models/release.go
parent6322d254e72c7c794f9d2e2325972249f187eae1 (diff)
downloadgitea-63ff61615ec6aaa25887f8ce605c9082c106a34b.tar.gz
gitea-63ff61615ec6aaa25887f8ce605c9082c106a34b.zip
Delete releases attachments if release is deleted (#6068)
* delete attachments from the database and file system * add migration * fix import statements * fix package name * remove conditional should in case the confi has been changed and the server restarted * simplify deletion of attachments in DB * fix CI build * fix review * add copyright in the proper place * fix review
Diffstat (limited to 'models/release.go')
-rw-r--r--models/release.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/models/release.go b/models/release.go
index dde6c17ea8..85a758becf 100644
--- a/models/release.go
+++ b/models/release.go
@@ -1,4 +1,5 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -6,6 +7,7 @@ package models
import (
"fmt"
+ "os"
"sort"
"strings"
@@ -357,6 +359,17 @@ func DeleteReleaseByID(id int64, doer *User, delTag bool) error {
return fmt.Errorf("LoadAttributes: %v", err)
}
+ if _, err := x.Delete(&Attachment{ReleaseID: id}); err != nil {
+ return err
+ }
+
+ for i := range rel.Attachments {
+ attachment := rel.Attachments[i]
+ if err := os.RemoveAll(attachment.LocalPath()); err != nil {
+ return err
+ }
+ }
+
mode, _ := AccessLevel(doer, rel.Repo)
if err := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
Action: api.HookReleaseDeleted,