diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/models/repo.go b/models/repo.go index 1c4f09c4..bad6f386 100644 --- a/models/repo.go +++ b/models/repo.go @@ -247,8 +247,8 @@ func (repo *Repository) HasAccess(u *User) bool { return has } -func (repo *Repository) IsOwnedBy(u *User) bool { - return repo.OwnerID == u.Id +func (repo *Repository) IsOwnedBy(userID int64) bool { + return repo.OwnerID == userID } // DescriptionHtml does special handles to description and return HTML string. @@ -923,13 +923,26 @@ 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 } for i := range issues { - if _, err = sess.Delete(&Comment{IssueId: issues[i].ID}); err != nil { + 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 } } @@ -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() } |