fix delete repo will hang on postgres (#1044)

This commit is contained in:
Lunny Xiao 2017-02-24 23:19:13 +08:00 committed by GitHub
parent 0602a44b27
commit c0ea3963be
2 changed files with 22 additions and 16 deletions

View file

@ -55,27 +55,30 @@ func (n *Notice) TrStr() string {
// CreateNotice creates new system notice.
func CreateNotice(tp NoticeType, desc string) error {
// prevent panic if database connection is not available at this point
if x == nil {
return fmt.Errorf("Could not save notice due database connection not being available: %d %s", tp, desc)
}
return createNotice(x, tp, desc)
}
func createNotice(e Engine, tp NoticeType, desc string) error {
n := &Notice{
Type: tp,
Description: desc,
}
_, err := x.Insert(n)
_, err := e.Insert(n)
return err
}
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
func CreateRepositoryNotice(desc string) error {
return CreateNotice(NoticeRepository, desc)
return createNotice(x, NoticeRepository, desc)
}
// RemoveAllWithNotice removes all directories in given path and
// creates a system notice when error occurs.
func RemoveAllWithNotice(title, path string) {
removeAllWithNotice(x, title, path)
}
func removeAllWithNotice(e Engine, title, path string) {
var err error
// 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:
@ -91,7 +94,7 @@ func RemoveAllWithNotice(title, path string) {
if err != nil {
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
log.Warn(desc)
if err = CreateRepositoryNotice(desc); err != nil {
if err = createNotice(e, NoticeRepository, desc); err != nil {
log.Error(4, "CreateRepositoryNotice: %v", err)
}
}