mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 05:25:35 +00:00
os: simplify EnsureDir() (#5871)
#5852 fixed an issue with error propagation in `os.EnsureDir()`. However, this function is basically identical to `os.MkdirAll()`, and can be replaced entirely with a call to it. We keep the function for backwards compatibility.
This commit is contained in:
committed by
Erik Grinaker
parent
3185bb8b22
commit
5d63765990
@@ -46,14 +46,7 @@ func Exit(s string) {
|
||||
// EnsureDir ensures the given directory exists, creating it if necessary.
|
||||
// Errors if the path already exists as a non-directory.
|
||||
func EnsureDir(dir string, mode os.FileMode) error {
|
||||
info, err := os.Stat(dir)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to stat %q: %w", dir, err)
|
||||
}
|
||||
if info != nil && !info.IsDir() {
|
||||
return fmt.Errorf("path %q already exists as a non-directory", dir)
|
||||
}
|
||||
err = os.MkdirAll(dir, mode)
|
||||
err := os.MkdirAll(dir, mode)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create directory %q: %w", dir, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user