From: qydysky Date: Mon, 10 Apr 2023 11:44:34 +0000 (+0800) Subject: update X-Git-Tag: v0.24.10 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=1c67e2bf47d3cfb71819f64a1cb315ecaab2f6f8;p=part%2F.git update --- diff --git a/file/FileWR.go b/file/FileWR.go index e78361a..8027ca2 100644 --- a/file/FileWR.go +++ b/file/FileWR.go @@ -351,14 +351,6 @@ func (t *File) getRWCloser() { } func (t *File) newPath() error { - /* - 如果filename路径不存在,就新建它 - */ - var exist func(string) bool = func(s string) bool { - _, err := os.Stat(s) - return !os.IsNotExist(err) - } - rawPath := "" if !filepath.IsAbs(t.Config.FilePath) { rawPath, _ = os.Getwd() @@ -373,7 +365,7 @@ func (t *File) newPath() error { } rawPath += string(os.PathSeparator) + p - if !exist(rawPath) { + if _, err := os.Stat(rawPath); os.IsNotExist(err) { err := os.Mkdir(rawPath, os.ModePerm) if err != nil { return err diff --git a/file/FileWR_test.go b/file/FileWR_test.go index 11ee154..35192dc 100644 --- a/file/FileWR_test.go +++ b/file/FileWR_test.go @@ -11,6 +11,22 @@ import ( "golang.org/x/text/encoding/unicode" ) +func TestNewPath2(t *testing.T) { + { + f := New("./test/test.log", 0, true) + f.Create() + if !f.IsExist() { + t.Fatal() + } + f.Delete() + } + { + f := New("./test/test.log", 0, true) + f.Create() + f.Delete() + } +} + func TestNewPath(t *testing.T) { if runtime.GOOS == "linux" { f := New("/tmp/test/test.log", 0, true)