Skip to content

Commit

Permalink
os: simplify EnsureDir() (#5871)
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
erikgrinaker committed Jan 6, 2021
1 parent 3185bb8 commit 5d63765
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions libs/os/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 5d63765

Please sign in to comment.