summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-14 03:07:20 +0800
committerUnknwon <u@gogs.io>2015-08-14 03:07:20 +0800
commit2cc9bc89698ab693a8ececa7f839483675bf88d6 (patch)
treed99edcb3651e7fb6a4cde02f3d6728516aaaaa66 /models/repo.go
parent0efe80d60d6a52d3a8e8a202ee951f55c7ebe71a (diff)
downloadgitea-2cc9bc89698ab693a8ececa7f839483675bf88d6.tar.gz
gitea-2cc9bc89698ab693a8ececa7f839483675bf88d6.zip
delete attachments when delete repo
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go
index 73ae6b54ac..bad6f38680 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -923,8 +923,9 @@ func DeleteRepository(uid, repoID int64, userName string) error {
return err
}
- // Delete comments.
+ // Delete comments and attachments.
issues := make([]*Issue, 0, 25)
+ attachmentPaths := make([]string, 0, len(issues))
if err = sess.Where("repo_id=?", repoID).Find(&issues); err != nil {
return err
}
@@ -932,6 +933,18 @@ func DeleteRepository(uid, repoID int64, userName string) error {
if _, err = sess.Delete(&Comment{IssueID: issues[i].ID}); err != nil {
return err
}
+
+ attachments := make([]*Attachment, 0, 5)
+ if err = sess.Where("issue_id=?", issues[i].ID).Find(&attachments); err != nil {
+ return err
+ }
+ for j := range attachments {
+ attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
+ }
+
+ if _, err = sess.Delete(&Attachment{IssueID: issues[i].ID}); err != nil {
+ return err
+ }
}
if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
@@ -957,6 +970,13 @@ func DeleteRepository(uid, repoID int64, userName string) error {
}
}
+ // Remove attachment files.
+ for i := range attachmentPaths {
+ if err = os.Remove(attachmentPaths[i]); err != nil {
+ log.Warn("delete attachment: %v", err)
+ }
+ }
+
return sess.Commit()
}