* Fix bug that release attachment files not deleted when deleting repository * improve code * add quote * improve code
This commit is contained in:
@ -1860,6 +1860,17 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attachments := make([]*Attachment, 0, 20)
|
||||||
|
if err = sess.Join("INNER", "`release`", "`release`.id = `attachment`.release_id").
|
||||||
|
Where("`release`.repo_id = ?", repoID).
|
||||||
|
Find(&attachments); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
releaseAttachments := make([]string, 0, len(attachments))
|
||||||
|
for i := 0; i < len(attachments); i++ {
|
||||||
|
releaseAttachments = append(releaseAttachments, attachments[i].LocalPath())
|
||||||
|
}
|
||||||
|
|
||||||
if err = deleteBeans(sess,
|
if err = deleteBeans(sess,
|
||||||
&Access{RepoID: repo.ID},
|
&Access{RepoID: repo.ID},
|
||||||
&Action{RepoID: repo.ID},
|
&Action{RepoID: repo.ID},
|
||||||
@ -1910,13 +1921,13 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentPaths := make([]string, 0, 20)
|
attachments = attachments[:0]
|
||||||
attachments := make([]*Attachment, 0, len(attachmentPaths))
|
|
||||||
if err = sess.Join("INNER", "issue", "issue.id = attachment.issue_id").
|
if err = sess.Join("INNER", "issue", "issue.id = attachment.issue_id").
|
||||||
Where("issue.repo_id = ?", repoID).
|
Where("issue.repo_id = ?", repoID).
|
||||||
Find(&attachments); err != nil {
|
Find(&attachments); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
attachmentPaths := make([]string, 0, len(attachments))
|
||||||
for j := range attachments {
|
for j := range attachments {
|
||||||
attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
|
attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
|
||||||
}
|
}
|
||||||
@ -1953,11 +1964,6 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove attachment files.
|
|
||||||
for i := range attachmentPaths {
|
|
||||||
removeAllWithNotice(sess, "Delete attachment", attachmentPaths[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove LFS objects
|
// Remove LFS objects
|
||||||
var lfsObjects []*LFSMetaObject
|
var lfsObjects []*LFSMetaObject
|
||||||
if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
|
if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
|
||||||
@ -1997,6 +2003,8 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
|||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sess.Close()
|
||||||
|
|
||||||
if org.IsOrganization() {
|
if org.IsOrganization() {
|
||||||
if err = PrepareWebhooks(repo, HookEventRepository, &api.RepositoryPayload{
|
if err = PrepareWebhooks(repo, HookEventRepository, &api.RepositoryPayload{
|
||||||
Action: api.HookRepoDeleted,
|
Action: api.HookRepoDeleted,
|
||||||
@ -2009,6 +2017,19 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
|||||||
go HookQueue.Add(repo.ID)
|
go HookQueue.Add(repo.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We should always delete the files after the database transaction succeed. If
|
||||||
|
// we delete the file but the database rollback, the repository will be borken.
|
||||||
|
|
||||||
|
// Remove issue attachment files.
|
||||||
|
for i := range attachmentPaths {
|
||||||
|
removeAllWithNotice(x, "Delete issue attachment", attachmentPaths[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove release attachment files.
|
||||||
|
for i := range releaseAttachments {
|
||||||
|
removeAllWithNotice(x, "Delete release attachment", releaseAttachments[i])
|
||||||
|
}
|
||||||
|
|
||||||
if len(repo.Avatar) > 0 {
|
if len(repo.Avatar) > 0 {
|
||||||
avatarPath := repo.CustomAvatarPath()
|
avatarPath := repo.CustomAvatarPath()
|
||||||
if com.IsExist(avatarPath) {
|
if com.IsExist(avatarPath) {
|
||||||
|
Reference in New Issue
Block a user