1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fix: fix bug of CreateDir

This commit is contained in:
dudaodong
2023-07-10 10:13:23 +08:00
parent 154ec56780
commit 7b744c299e
5 changed files with 20 additions and 11 deletions

View File

@@ -52,7 +52,8 @@ func CreateFile(path string) bool {
// CreateDir create directory in absolute path. param `absPath` like /a/, /a/b/.
// Play: https://go.dev/play/p/qUuCe1OGQnM
func CreateDir(absPath string) error {
return os.MkdirAll(path.Dir(absPath), os.ModePerm)
// return os.MkdirAll(path.Dir(absPath), os.ModePerm)
return os.MkdirAll(absPath, os.ModePerm)
}
// IsDir checks if the path is directory or not.

View File

@@ -39,7 +39,7 @@ func ExampleCreateFile() {
func ExampleCreateDir() {
pwd, _ := os.Getwd()
dirPath := pwd + "/test_xxx/"
dirPath := pwd + "/createdir/a/b"
result1 := IsExist(dirPath)
@@ -48,16 +48,22 @@ func ExampleCreateDir() {
return
}
result2 := IsExist(dirPath)
os.Remove(dirPath)
result2 := IsExist(pwd + "/createdir/")
result3 := IsExist(pwd + "/createdir/a")
result4 := IsExist(pwd + "/createdir/a/b")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
os.RemoveAll(pwd + "/createdir/")
// Output:
// false
// true
// true
// true
}
func ExampleIsDir() {

View File

@@ -50,7 +50,7 @@ func TestCreateDir(t *testing.T) {
t.FailNow()
}
dirPath := pwd + "/a/"
dirPath := pwd + "/a/b"
err = CreateDir(dirPath)
if err != nil {
t.Error(err)
@@ -58,7 +58,9 @@ func TestCreateDir(t *testing.T) {
}
assert.Equal(true, IsExist(dirPath))
os.Remove(dirPath)
os.RemoveAll(pwd + "/a")
assert.Equal(false, IsExist(dirPath))
}