improve temporary path producing from gfile.Join to gfile.TempDir

This commit is contained in:
John 2020-03-28 00:41:12 +08:00
parent f1f575fd5c
commit ddcb7121c1
17 changed files with 47 additions and 47 deletions

View File

@ -44,8 +44,8 @@ func Test_Gzip_UnGzip(t *testing.T) {
func Test_Gzip_UnGzip_File(t *testing.T) {
srcPath := gdebug.TestDataPath("gzip", "file.txt")
dstPath1 := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), "gzip.zip")
dstPath2 := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), "file.txt")
dstPath1 := gfile.TempDir(gtime.TimestampNanoStr(), "gzip.zip")
dstPath2 := gfile.TempDir(gtime.TimestampNanoStr(), "file.txt")
// Compress.
gtest.C(t, func(t *gtest.T) {

View File

@ -29,7 +29,7 @@ func Test_ZipPath(t *testing.T) {
t.Assert(gfile.Exists(dstPath), true)
defer gfile.Remove(dstPath)
tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
tempDirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(tempDirPath)
t.Assert(err, nil)
@ -58,7 +58,7 @@ func Test_ZipPath(t *testing.T) {
t.Assert(gfile.Exists(dstPath), true)
defer gfile.Remove(dstPath)
tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
tempDirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(tempDirPath)
t.Assert(err, nil)
@ -93,7 +93,7 @@ func Test_ZipPath(t *testing.T) {
t.Assert(gfile.Exists(dstPath), true)
defer gfile.Remove(dstPath)
tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
tempDirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(tempDirPath)
t.Assert(err, nil)
@ -131,7 +131,7 @@ func Test_ZipPathWriter(t *testing.T) {
t.Assert(err, nil)
t.AssertGT(writer.Len(), 0)
tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
tempDirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(tempDirPath)
t.Assert(err, nil)

View File

@ -39,7 +39,7 @@ func Test_Config2(t *testing.T) {
// relative path
gtest.C(t, func(t *gtest.T) {
var err error
dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath)
t.Assert(err, nil)
defer gfile.Remove(dirPath)
@ -63,7 +63,7 @@ func Test_Config2(t *testing.T) {
// relative path, config folder
gtest.C(t, func(t *gtest.T) {
var err error
dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath)
t.Assert(err, nil)
defer gfile.Remove(dirPath)
@ -89,7 +89,7 @@ func Test_Config2(t *testing.T) {
func Test_Config3(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var err error
dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath)
t.Assert(err, nil)
defer gfile.Remove(dirPath)
@ -113,7 +113,7 @@ func Test_Config3(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var err error
dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath)
t.Assert(err, nil)
defer gfile.Remove(dirPath)

View File

@ -23,7 +23,7 @@ func Test_Database(t *testing.T) {
)
gtest.C(t, func(t *gtest.T) {
var err error
dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath)
t.Assert(err, nil)
defer gfile.Remove(dirPath)

View File

@ -24,7 +24,7 @@ func Test_Redis(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var err error
dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dirPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath)
t.Assert(err, nil)
defer gfile.Remove(dirPath)

View File

@ -23,7 +23,7 @@ import (
func Test_Log(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
logDir := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
logDir := gfile.TempDir(gtime.TimestampNanoStr())
p := ports.PopRand()
s := g.Server(p)
s.BindHandler("/hello", func(r *ghttp.Request) {

View File

@ -21,7 +21,7 @@ import (
)
func Test_Params_File_Single(t *testing.T) {
dstDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dstDirPath := gfile.TempDir(gtime.TimestampNanoStr())
p := ports.PopRand()
s := g.Server(p)
s.BindHandler("/upload/single", func(r *ghttp.Request) {
@ -75,7 +75,7 @@ func Test_Params_File_Single(t *testing.T) {
}
func Test_Params_File_CustomName(t *testing.T) {
dstDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dstDirPath := gfile.TempDir(gtime.TimestampNanoStr())
p := ports.PopRand()
s := g.Server(p)
s.BindHandler("/upload/single", func(r *ghttp.Request) {
@ -112,7 +112,7 @@ func Test_Params_File_CustomName(t *testing.T) {
}
func Test_Params_File_Batch(t *testing.T) {
dstDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dstDirPath := gfile.TempDir(gtime.TimestampNanoStr())
p := ports.PopRand()
s := g.Server(p)
s.BindHandler("/upload/batch", func(r *ghttp.Request) {

View File

@ -362,7 +362,7 @@ func TestCfg_FilePath(t *testing.T) {
func TestCfg_Get(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var err error
configPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
configPath := gfile.TempDir(gtime.TimestampNanoStr())
err = gfile.Mkdir(configPath)
t.Assert(err, nil)
defer gfile.Remove(configPath)

View File

@ -49,8 +49,8 @@ func Test_CopyFile(t *testing.T) {
})
// Content replacement.
gtest.C(t, func(t *gtest.T) {
src := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dst := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
src := gfile.TempDir(gtime.TimestampNanoStr())
dst := gfile.TempDir(gtime.TimestampNanoStr())
srcContent := "1"
dstContent := "1"
gfile.PutContents(src, srcContent)
@ -115,8 +115,8 @@ func Test_CopyDir(t *testing.T) {
})
// Content replacement.
gtest.C(t, func(t *gtest.T) {
src := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), gtime.TimestampNanoStr())
dst := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), gtime.TimestampNanoStr())
src := gfile.TempDir(gtime.TimestampNanoStr(), gtime.TimestampNanoStr())
dst := gfile.TempDir(gtime.TimestampNanoStr(), gtime.TimestampNanoStr())
srcContent := "1"
dstContent := "1"
gfile.PutContents(src, srcContent)

View File

@ -12,7 +12,7 @@ import (
func Test_ConcurrentOS(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
defer gfile.Remove(path)
f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil)
@ -43,7 +43,7 @@ func Test_ConcurrentOS(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
defer gfile.Remove(path)
f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil)
@ -64,7 +64,7 @@ func Test_ConcurrentOS(t *testing.T) {
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000)
})
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
defer gfile.Remove(path)
f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil)
@ -92,7 +92,7 @@ func Test_ConcurrentOS(t *testing.T) {
})
// DATA RACE
//gtest.C(t, func(t *gtest.T) {
// path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
// path := gfile.TempDir(gtime.TimestampNanoStr())
// defer gfile.Remove(path)
// f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
// t.Assert(err, nil)
@ -130,7 +130,7 @@ func Test_ConcurrentOS(t *testing.T) {
func Test_ConcurrentGFPool(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
defer gfile.Remove(path)
f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil)
@ -152,7 +152,7 @@ func Test_ConcurrentGFPool(t *testing.T) {
})
// DATA RACE
//gtest.C(t, func(t *gtest.T) {
// path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
// path := gfile.TempDir(gtime.TimestampNanoStr())
// defer gfile.Remove(path)
// f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
// t.Assert(err, nil)

View File

@ -21,7 +21,7 @@ import (
func TestWatcher_AddOnce(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
value := gtype.New()
path := gfile.Join(gfile.TempDir(), gconv.String(gtime.TimestampNano()))
path := gfile.TempDir(gconv.String(gtime.TimestampNano()))
err := gfile.PutContents(path, "init")
t.Assert(err, nil)
defer gfile.Remove(path)

View File

@ -29,7 +29,7 @@ func Test_To(t *testing.T) {
func Test_Path(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -47,7 +47,7 @@ func Test_Path(t *testing.T) {
func Test_Cat(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
cat := "category"
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -64,7 +64,7 @@ func Test_Cat(t *testing.T) {
func Test_Level(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -81,7 +81,7 @@ func Test_Level(t *testing.T) {
func Test_Skip(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -99,7 +99,7 @@ func Test_Skip(t *testing.T) {
func Test_Stack(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -117,7 +117,7 @@ func Test_Stack(t *testing.T) {
func Test_StackWithFilter(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -131,7 +131,7 @@ func Test_StackWithFilter(t *testing.T) {
t.Assert(gstr.Count(content, "Stack"), 1)
})
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -148,7 +148,7 @@ func Test_StackWithFilter(t *testing.T) {
func Test_Header(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -161,7 +161,7 @@ func Test_Header(t *testing.T) {
t.Assert(gstr.Count(content, "1 2 3"), 1)
})
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -177,7 +177,7 @@ func Test_Header(t *testing.T) {
func Test_Line(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -192,7 +192,7 @@ func Test_Line(t *testing.T) {
t.Assert(gstr.Contains(content, gfile.Separator), true)
})
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -210,7 +210,7 @@ func Test_Line(t *testing.T) {
func Test_Async(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
@ -228,7 +228,7 @@ func Test_Async(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)

View File

@ -22,7 +22,7 @@ func Test_Concurrent(t *testing.T) {
l := glog.New()
s := "@1234567890#"
f := "test.log"
p := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
p := gfile.TempDir(gtime.TimestampNanoStr())
t.Assert(l.SetPath(p), nil)
defer gfile.Remove(p)
wg := sync.WaitGroup{}

View File

@ -20,7 +20,7 @@ import (
func Test_Rotate_Size(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
l := glog.New()
p := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
p := gfile.TempDir(gtime.TimestampNanoStr())
err := l.SetConfigWithMap(g.Map{
"Path": p,
"File": "access.log",
@ -58,7 +58,7 @@ func Test_Rotate_Size(t *testing.T) {
func Test_Rotate_Expire(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
l := glog.New()
p := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
p := gfile.TempDir(gtime.TimestampNanoStr())
err := l.SetConfigWithMap(g.Map{
"Path": p,
"File": "access.log",

View File

@ -43,7 +43,7 @@ var (
commReceiveQueues = gmap.NewStrAnyMap(true)
// commPidFolderPath specifies the folder path storing pid to port mapping files.
commPidFolderPath = gfile.Join(gfile.TempDir(), "gproc")
commPidFolderPath = gfile.TempDir("gproc")
)
func init() {

View File

@ -44,7 +44,7 @@ func Test_Pack(t *testing.T) {
func Test_PackToFile(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
srcPath := gdebug.TestDataPath("files")
dstPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr())
dstPath := gfile.TempDir(gtime.TimestampNanoStr())
err := gres.PackToFile(srcPath, dstPath)
t.Assert(err, nil)

View File

@ -35,7 +35,7 @@ type StorageFile struct {
}
var (
DefaultStorageFilePath = gfile.Join(gfile.TempDir(), "gsessions")
DefaultStorageFilePath = gfile.TempDir("gsessions")
DefaultStorageFileCryptoKey = []byte("Session storage file crypto key!")
DefaultStorageFileCryptoEnabled = false
DefaultStorageFileLoopInterval = 10 * time.Second