diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2016-05-06 16:48:18 -0300 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-05-06 15:48:18 -0400 |
commit | d8612f7704c8efd011c105493cde00f823033517 (patch) | |
tree | 92aa7724539921cce3f61e7db0a9fef8185f5907 /models/admin.go | |
parent | 0a78d99a4db96c5181678acc46ca3dcc0d10c2b2 (diff) | |
download | gitea-d8612f7704c8efd011c105493cde00f823033517.tar.gz gitea-d8612f7704c8efd011c105493cde00f823033517.zip |
Fix remove folder issues, including initialization failling. (#2969)
- Prevent panic on creating notice if database is not available
- Prevent incorrect folder on Windows ("/" instead of "\")
Diffstat (limited to 'models/admin.go')
-rw-r--r-- | models/admin.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/models/admin.go b/models/admin.go index d9e8e529ed..3d27e554d0 100644 --- a/models/admin.go +++ b/models/admin.go @@ -52,6 +52,11 @@ 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) + } + n := &Notice{ Type: tp, Description: desc, @@ -70,6 +75,9 @@ func CreateRepositoryNotice(desc string) error { func RemoveAllWithNotice(title, path string) { var err error if setting.IsWindows { + // usually Go automatically converts "/" to "\" in path on Windows + // but since we are running it manually, it's better to convert to prevent problems + path = strings.Replace(path, "/", "\\", -1) err = exec.Command("cmd", "/C", "rmdir", "/S", "/Q", path).Run() } else { err = os.RemoveAll(path) |