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 "\")
This commit is contained in:
parent
0a78d99a4d
commit
d8612f7704
1 changed files with 8 additions and 0 deletions
|
@ -52,6 +52,11 @@ 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
|
||||||
|
if x == nil {
|
||||||
|
return fmt.Errorf("Could not save notice due database connection not being available: %d %s", tp, desc)
|
||||||
|
}
|
||||||
|
|
||||||
n := &Notice{
|
n := &Notice{
|
||||||
Type: tp,
|
Type: tp,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
|
@ -70,6 +75,9 @@ func CreateRepositoryNotice(desc string) error {
|
||||||
func RemoveAllWithNotice(title, path string) {
|
func RemoveAllWithNotice(title, path string) {
|
||||||
var err error
|
var err error
|
||||||
if setting.IsWindows {
|
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()
|
err = exec.Command("cmd", "/C", "rmdir", "/S", "/Q", path).Run()
|
||||||
} else {
|
} else {
|
||||||
err = os.RemoveAll(path)
|
err = os.RemoveAll(path)
|
||||||
|
|
Reference in a new issue