Browse Source

delete attachments when delete repo

pull/1484/head
Unknwon 10 years ago
parent
commit
2cc9bc8969
  1. 22
      models/repo.go

22
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()
}

Loading…
Cancel
Save