Source File
path.go
Belonging Package
os
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package os
import (
)
// MkdirAll creates a directory named path,
// along with any necessary parents, and returns nil,
// or else returns an error.
// The permission bits perm (before umask) are used for all
// directories that MkdirAll creates.
// If path is already a directory, MkdirAll does nothing
// and returns nil.
func ( string, FileMode) error {
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
, := Stat()
if == nil {
if .IsDir() {
return nil
}
return &PathError{Op: "mkdir", Path: , Err: syscall.ENOTDIR}
}
// Slow path: make sure parent exists and then call Mkdir for path.
:= len()
for > 0 && IsPathSeparator([-1]) { // Skip trailing path separator.
--
}
:=
for > 0 && !IsPathSeparator([-1]) { // Scan backward over element.
--
}
if > 1 {
// Create parent.
= (fixRootDirectory([:-1]), )
if != nil {
return
}
}
// Parent now exists; invoke Mkdir and use its result.
= Mkdir(, )
if != nil {
// Handle arguments like "foo/." by
// double-checking that directory doesn't exist.
, := Lstat()
if == nil && .IsDir() {
return nil
}
return
}
return nil
}
// RemoveAll removes path and any children it contains.
// It removes everything it can but returns the first error
// it encounters. If the path does not exist, RemoveAll
// returns nil (no error).
// If there is an error, it will be of type *PathError.
func ( string) error {
return removeAll()
}
// endsWithDot reports whether the final component of path is ".".
func ( string) bool {
if == "." {
return true
}
if len() >= 2 && [len()-1] == '.' && IsPathSeparator([len()-2]) {
return true
}
return false
}
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |