Skip to content

Commit

Permalink
os: recomment MkdirAll
Browse files Browse the repository at this point in the history
The internal comments are not completely precise about
what is going on, and they are causing confusion.

Fixes golang#8283.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/151460043
  • Loading branch information
rsc authored and wheatman committed Jul 23, 2018
1 parent 651e6c6 commit fbc73a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/os/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// If path is already a directory, MkdirAll does nothing
// and returns nil.
func MkdirAll(path string, perm FileMode) error {
// If path exists, stop with success or error.
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
dir, err := Stat(path)
if err == nil {
if dir.IsDir() {
Expand All @@ -26,7 +26,7 @@ func MkdirAll(path string, perm FileMode) error {
return &PathError{"mkdir", path, syscall.ENOTDIR}
}

// Doesn't already exist; make sure parent does.
// Slow path: make sure parent exists and then call Mkdir for path.
i := len(path)
for i > 0 && IsPathSeparator(path[i-1]) { // Skip trailing path separator.
i--
Expand All @@ -45,7 +45,7 @@ func MkdirAll(path string, perm FileMode) error {
}
}

// Now parent exists, try to create.
// Parent now exists; invoke Mkdir and use its result.
err = Mkdir(path, perm)
if err != nil {
// Handle arguments like "foo/." by
Expand Down

0 comments on commit fbc73a4

Please sign in to comment.