forked from gitea/gitea
delete attachments when delete repo
This commit is contained in:
parent
0efe80d60d
commit
2cc9bc8969
|
@ -923,8 +923,9 @@ func DeleteRepository(uid, repoID int64, userName string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete comments.
|
// Delete comments and attachments.
|
||||||
issues := make([]*Issue, 0, 25)
|
issues := make([]*Issue, 0, 25)
|
||||||
|
attachmentPaths := make([]string, 0, len(issues))
|
||||||
if err = sess.Where("repo_id=?", repoID).Find(&issues); err != nil {
|
if err = sess.Where("repo_id=?", repoID).Find(&issues); err != nil {
|
||||||
return err
|
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 {
|
if _, err = sess.Delete(&Comment{IssueID: issues[i].ID}); err != nil {
|
||||||
return err
|
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 {
|
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()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue