Skip to content

Commit c0ea396

Browse files
authored
fix delete repo will hang on postgres (#1044)
1 parent 0602a44 commit c0ea396

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

models/admin.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,30 @@ func (n *Notice) TrStr() string {
5555

5656
// CreateNotice creates new system notice.
5757
func CreateNotice(tp NoticeType, desc string) error {
58-
// prevent panic if database connection is not available at this point
59-
if x == nil {
60-
return fmt.Errorf("Could not save notice due database connection not being available: %d %s", tp, desc)
61-
}
58+
return createNotice(x, tp, desc)
59+
}
6260

61+
func createNotice(e Engine, tp NoticeType, desc string) error {
6362
n := &Notice{
6463
Type: tp,
6564
Description: desc,
6665
}
67-
_, err := x.Insert(n)
66+
_, err := e.Insert(n)
6867
return err
6968
}
7069

7170
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
7271
func CreateRepositoryNotice(desc string) error {
73-
return CreateNotice(NoticeRepository, desc)
72+
return createNotice(x, NoticeRepository, desc)
7473
}
7574

7675
// RemoveAllWithNotice removes all directories in given path and
7776
// creates a system notice when error occurs.
7877
func RemoveAllWithNotice(title, path string) {
78+
removeAllWithNotice(x, title, path)
79+
}
80+
81+
func removeAllWithNotice(e Engine, title, path string) {
7982
var err error
8083
// workaround for Go not being able to remove read-only files/folders: https://github.com/golang/go/issues/9606
8184
// 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) {
9194
if err != nil {
9295
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
9396
log.Warn(desc)
94-
if err = CreateRepositoryNotice(desc); err != nil {
97+
if err = createNotice(e, NoticeRepository, desc); err != nil {
9598
log.Error(4, "CreateRepositoryNotice: %v", err)
9699
}
97100
}

models/repo.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,18 @@ func (repo *Repository) ComposeMetas() map[string]string {
412412
}
413413

414414
// DeleteUncyclo removes the actual and local copy of repository wiki.
415-
func (repo *Repository) DeleteUncyclo() {
415+
func (repo *Repository) DeleteUncyclo() error {
416+
return repo.deleteUncyclo(x)
417+
}
418+
419+
func (repo *Repository) deleteUncyclo(e Engine) error {
416420
wikiPaths := []string{repo.UncycloPath(), repo.LocalUncycloPath()}
417421
for _, wikiPath := range wikiPaths {
418-
RemoveAllWithNotice("Delete repository wiki", wikiPath)
422+
removeAllWithNotice(e, "Delete repository wiki", wikiPath)
419423
}
420424

421-
x.Where("repo_id = ?", repo.ID).And("type = ?", UnitTypeUncyclo).Delete(new(RepoUnit))
425+
_, err := e.Where("repo_id = ?", repo.ID).And("type = ?", UnitTypeUncyclo).Delete(new(RepoUnit))
426+
return err
422427
}
423428

424429
func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
@@ -1620,27 +1625,25 @@ func DeleteRepository(uid, repoID int64) error {
16201625
return err
16211626
}
16221627

1623-
// Remove repository files.
1628+
// FIXME: Remove repository files should be executed after transaction succeed.
16241629
repoPath := repo.repoPath(sess)
1625-
RemoveAllWithNotice("Delete repository files", repoPath)
1630+
removeAllWithNotice(sess, "Delete repository files", repoPath)
16261631

1627-
repo.DeleteUncyclo()
1632+
repo.deleteUncyclo(sess)
16281633

16291634
// Remove attachment files.
16301635
for i := range attachmentPaths {
1631-
RemoveAllWithNotice("Delete attachment", attachmentPaths[i])
1636+
removeAllWithNotice(sess, "Delete attachment", attachmentPaths[i])
16321637
}
16331638

16341639
// Remove LFS objects
16351640
var lfsObjects []*LFSMetaObject
1636-
16371641
if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
16381642
return err
16391643
}
16401644

16411645
for _, v := range lfsObjects {
16421646
count, err := sess.Count(&LFSMetaObject{Oid: v.Oid})
1643-
16441647
if err != nil {
16451648
return err
16461649
}

0 commit comments

Comments
 (0)