aboutsummaryrefslogtreecommitdiff
path: root/models/admin.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/admin.go')
-rw-r--r--models/admin.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/models/admin.go b/models/admin.go
index 1d6bf629..7756cd6a 100644
--- a/models/admin.go
+++ b/models/admin.go
@@ -5,12 +5,17 @@
package models
import (
+ "fmt"
+ "os"
+ "os/exec"
"strings"
"time"
"github.com/Unknwon/com"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/log"
+ "github.com/gogits/gogs/modules/setting"
)
type NoticeType int
@@ -47,6 +52,25 @@ func CreateRepositoryNotice(desc string) error {
return CreateNotice(NOTICE_REPOSITORY, desc)
}
+// RemoveAllWithNotice removes all directories in given path and
+// creates a system notice when error occurs.
+func RemoveAllWithNotice(title, path string) {
+ var err error
+ if setting.IsWindows {
+ err = exec.Command("cmd", "/C", "rmdir", "/S", "/Q", path).Run()
+ } else {
+ err = os.RemoveAll(path)
+ }
+
+ if err != nil {
+ desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
+ log.Warn(desc)
+ if err = CreateRepositoryNotice(desc); err != nil {
+ log.Error(4, "CreateRepositoryNotice: %v", err)
+ }
+ }
+}
+
// CountNotices returns number of notices.
func CountNotices() int64 {
count, _ := x.Count(new(Notice))