]> 127.0.0.1 Git - part/.git/commitdiff
update v0.24.10
authorqydysky <qydysky@foxmail.com>
Mon, 10 Apr 2023 11:44:34 +0000 (19:44 +0800)
committerqydysky <qydysky@foxmail.com>
Mon, 10 Apr 2023 11:44:34 +0000 (19:44 +0800)
file/FileWR.go
file/FileWR_test.go

index e78361a26f2f238b7df04ef05b5145dd5923c0d9..8027ca2a3eaaf5b34aadf0793ea5bf8b1991d5ff 100644 (file)
@@ -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
index 11ee154b11c024fccf8fb7e50814fde9ea722ad2..35192dcb75eb1020d8bde562c77713ed2d1bd542 100644 (file)
@@ -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)