28 lines
434 B
Go
28 lines
434 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// EnsureDir checks if a directory exists and creates it if it doesn't.
|
|
// Returns any error encountered during directory creation.
|
|
func EnsureDir(path string) error {
|
|
path = filepath.Clean(path)
|
|
|
|
info, err := os.Stat(path)
|
|
|
|
if err == nil {
|
|
if info.IsDir() {
|
|
return nil
|
|
}
|
|
return os.ErrExist
|
|
}
|
|
|
|
if !os.IsNotExist(err) {
|
|
return err
|
|
}
|
|
|
|
return os.MkdirAll(path, 0755)
|
|
}
|