diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/models/repo.go b/models/repo.go index 1c4f09c4..9aed7d7d 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. @@ -458,7 +458,9 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { } func createUpdateHook(repoPath string) error { - return ioutil.WriteFile(path.Join(repoPath, "hooks/update"), + hookPath := path.Join(repoPath, "hooks/update") + os.MkdirAll(path.Dir(hookPath), os.ModePerm) + return ioutil.WriteFile(hookPath, []byte(fmt.Sprintf(_TPL_UPDATE_HOOK, setting.ScriptType, "\""+appPath+"\"", setting.CustomConf)), 0777) } @@ -923,13 +925,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 +972,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() } |