refactor file|path (#1409)
Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -10,19 +10,19 @@ import (
|
||||
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
// MaybeCreateFile creates file if not exists
|
||||
func MaybeCreateFile(dir, subdir, file string) (fp *os.File, created bool, err error) {
|
||||
logx.Must(util.MkdirIfNotExist(path.Join(dir, subdir)))
|
||||
logx.Must(pathx.MkdirIfNotExist(path.Join(dir, subdir)))
|
||||
fpath := path.Join(dir, subdir, file)
|
||||
if util.FileExists(fpath) {
|
||||
if pathx.FileExists(fpath) {
|
||||
fmt.Printf("%s exists, ignored generation\n", fpath)
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
fp, err = util.CreateIfNotExist(fpath)
|
||||
fp, err = pathx.CreateIfNotExist(fpath)
|
||||
created = err == nil
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user