diff options
author | Russ Cox <rsc@golang.org> | 2014-10-06 15:49:33 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-10-06 15:49:33 -0400 |
commit | 746f251c178ec15bfdb422ddc55af8f343b1f593 (patch) | |
tree | 080043b42e646fb534e5f31d57217dff2792acb0 | |
parent | 591f36004682e1adf977cb5d9f12c98b560924d7 (diff) | |
download | go-746f251c178ec15bfdb422ddc55af8f343b1f593.tar.gz |
os: recomment MkdirAll
The internal comments are not completely precise about
what is going on, and they are causing confusion.
Fixes issue 8283.
LGTM=r
R=r
CC=golang-codereviews
https://codereview.appspot.com/151460043
-rw-r--r-- | src/os/path.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/os/path.go b/src/os/path.go index 24a3415b4..84a3be334 100644 --- a/src/os/path.go +++ b/src/os/path.go @@ -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() { @@ -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-- @@ -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 |