qbtrade/pkg/util/dir.go

24 lines
283 B
Go
Raw Normal View History

2024-06-27 14:42:38 +00:00
package util
import (
"fmt"
"os"
)
func SafeMkdirAll(p string) error {
st, err := os.Stat(p)
if err == nil {
if !st.IsDir() {
return fmt.Errorf("path %s is not a directory", p)
}
return nil
}
if os.IsNotExist(err) {
return os.MkdirAll(p, 0755)
}
return nil
}