Skip to content

Commit 08f7fde

Browse files
appleboylunny
authored andcommitted
refactor: remove workaround after the golang 1.7 release. (#1349)
* refactor: remove workaround after the golang 1.7 release. * remove unused import. Signed-off-by: Bo-Yi Wu <[email protected]> * refactor: Add remove function. * refactor: rename * refactor: update build flag
1 parent 6a451a2 commit 08f7fde

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

models/admin.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ package models
66

77
import (
88
"fmt"
9-
"os"
10-
"os/exec"
11-
"strings"
129
"time"
1310

11+
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/util"
13+
1414
"github.com/Unknwon/com"
1515
"github.com/go-xorm/xorm"
16-
17-
"code.gitea.io/gitea/modules/log"
18-
"code.gitea.io/gitea/modules/setting"
1916
)
2017

2118
//NoticeType describes the notice type
@@ -79,19 +76,7 @@ func RemoveAllWithNotice(title, path string) {
7976
}
8077

8178
func removeAllWithNotice(e Engine, title, path string) {
82-
var err error
83-
// workaround for Go not being able to remove read-only files/folders: https://github.com/golang/go/issues/9606
84-
// this bug should be fixed on Go 1.7, so the workaround should be removed when Gogs don't support Go 1.6 anymore:
85-
// https://github.com/golang/go/commit/2ffb3e5d905b5622204d199128dec06cefd57790
86-
if setting.IsWindows {
87-
// converting "/" to "\" in path on Windows
88-
path = strings.Replace(path, "/", "\\", -1)
89-
err = exec.Command("cmd", "/C", "rmdir", "/S", "/Q", path).Run()
90-
} else {
91-
err = os.RemoveAll(path)
92-
}
93-
94-
if err != nil {
79+
if err := util.RemoveAll(path); err != nil {
9580
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
9681
log.Warn(desc)
9782
if err = createNotice(e, NoticeRepository, desc); err != nil {

modules/util/remove.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// +build !windows,!go1.7 go1.7
2+
3+
// Copyright 2017 The Gitea Authors. All rights reserved.
4+
// Use of this source code is governed by a MIT-style
5+
// license that can be found in the LICENSE file.
6+
7+
package util
8+
9+
import "os"
10+
11+
// RemoveAll files from Go version 1.7 onward
12+
func RemoveAll(path string) error {
13+
return os.RemoveAll(path)
14+
}

modules/util/remove_windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// +build windows,!go1.7
2+
3+
// Copyright 2017 The Gitea Authors. All rights reserved.
4+
// Use of this source code is governed by a MIT-style
5+
// license that can be found in the LICENSE file.
6+
7+
package util
8+
9+
// RemoveAll files from path on windows
10+
// workaround for Go not being able to remove read-only files/folders: https://github.com/golang/go/issues/9606
11+
// this bug should be fixed on Go 1.7, so the workaround should be removed when Gitea don't support Go 1.6 anymore:
12+
// https://github.com/golang/go/commit/2ffb3e5d905b5622204d199128dec06cefd57790
13+
func RemoveAll(path string) error {
14+
path = strings.Replace(path, "/", "\\", -1)
15+
return exec.Command("cmd", "/C", "rmdir", "/S", "/Q", path).Run()
16+
}

0 commit comments

Comments
 (0)