fix delete repo will hang on postgres (#1044)
This commit is contained in:
parent
0602a44b27
commit
c0ea3963be
2 changed files with 22 additions and 16 deletions
|
@ -55,27 +55,30 @@ func (n *Notice) TrStr() string {
|
||||||
|
|
||||||
// CreateNotice creates new system notice.
|
// CreateNotice creates new system notice.
|
||||||
func CreateNotice(tp NoticeType, desc string) error {
|
func CreateNotice(tp NoticeType, desc string) error {
|
||||||
// prevent panic if database connection is not available at this point
|
return createNotice(x, tp, desc)
|
||||||
if x == nil {
|
}
|
||||||
return fmt.Errorf("Could not save notice due database connection not being available: %d %s", tp, desc)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
func createNotice(e Engine, tp NoticeType, desc string) error {
|
||||||
n := &Notice{
|
n := &Notice{
|
||||||
Type: tp,
|
Type: tp,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
}
|
}
|
||||||
_, err := x.Insert(n)
|
_, err := e.Insert(n)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
|
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
|
||||||
func CreateRepositoryNotice(desc string) error {
|
func CreateRepositoryNotice(desc string) error {
|
||||||
return CreateNotice(NoticeRepository, desc)
|
return createNotice(x, NoticeRepository, desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveAllWithNotice removes all directories in given path and
|
// RemoveAllWithNotice removes all directories in given path and
|
||||||
// creates a system notice when error occurs.
|
// creates a system notice when error occurs.
|
||||||
func RemoveAllWithNotice(title, path string) {
|
func RemoveAllWithNotice(title, path string) {
|
||||||
|
removeAllWithNotice(x, title, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeAllWithNotice(e Engine, title, path string) {
|
||||||
var err error
|
var err error
|
||||||
// workaround for Go not being able to remove read-only files/folders: https://github.com/golang/go/issues/9606
|
// workaround for Go not being able to remove read-only files/folders: https://github.com/golang/go/issues/9606
|
||||||
// this bug should be fixed on Go 1.7, so the workaround should be removed when Gogs don't support Go 1.6 anymore:
|
// this bug should be fixed on Go 1.7, so the workaround should be removed when Gogs don't support Go 1.6 anymore:
|
||||||
|
@ -91,7 +94,7 @@ func RemoveAllWithNotice(title, path string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
|
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
|
||||||
log.Warn(desc)
|
log.Warn(desc)
|
||||||
if err = CreateRepositoryNotice(desc); err != nil {
|
if err = createNotice(e, NoticeRepository, desc); err != nil {
|
||||||
log.Error(4, "CreateRepositoryNotice: %v", err)
|
log.Error(4, "CreateRepositoryNotice: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,13 +412,18 @@ func (repo *Repository) ComposeMetas() map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteWiki removes the actual and local copy of repository wiki.
|
// DeleteWiki removes the actual and local copy of repository wiki.
|
||||||
func (repo *Repository) DeleteWiki() {
|
func (repo *Repository) DeleteWiki() error {
|
||||||
|
return repo.deleteWiki(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) deleteWiki(e Engine) error {
|
||||||
wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
|
wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
|
||||||
for _, wikiPath := range wikiPaths {
|
for _, wikiPath := range wikiPaths {
|
||||||
RemoveAllWithNotice("Delete repository wiki", wikiPath)
|
removeAllWithNotice(e, "Delete repository wiki", wikiPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
x.Where("repo_id = ?", repo.ID).And("type = ?", UnitTypeWiki).Delete(new(RepoUnit))
|
_, err := e.Where("repo_id = ?", repo.ID).And("type = ?", UnitTypeWiki).Delete(new(RepoUnit))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
|
func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
|
||||||
|
@ -1620,27 +1625,25 @@ func DeleteRepository(uid, repoID int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove repository files.
|
// FIXME: Remove repository files should be executed after transaction succeed.
|
||||||
repoPath := repo.repoPath(sess)
|
repoPath := repo.repoPath(sess)
|
||||||
RemoveAllWithNotice("Delete repository files", repoPath)
|
removeAllWithNotice(sess, "Delete repository files", repoPath)
|
||||||
|
|
||||||
repo.DeleteWiki()
|
repo.deleteWiki(sess)
|
||||||
|
|
||||||
// Remove attachment files.
|
// Remove attachment files.
|
||||||
for i := range attachmentPaths {
|
for i := range attachmentPaths {
|
||||||
RemoveAllWithNotice("Delete attachment", attachmentPaths[i])
|
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 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range lfsObjects {
|
for _, v := range lfsObjects {
|
||||||
count, err := sess.Count(&LFSMetaObject{Oid: v.Oid})
|
count, err := sess.Count(&LFSMetaObject{Oid: v.Oid})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue