...
Source file
src/os/path.go
Documentation: os
1
2
3
4
5 package os
6
7 import (
8 "syscall"
9 )
10
11
12
13
14
15
16
17
18 func MkdirAll(path string, perm FileMode) error {
19
20 dir, err := Stat(path)
21 if err == nil {
22 if dir.IsDir() {
23 return nil
24 }
25 return &PathError{Op: "mkdir", Path: path, Err: syscall.ENOTDIR}
26 }
27
28
29 i := len(path)
30 for i > 0 && IsPathSeparator(path[i-1]) {
31 i--
32 }
33
34 j := i
35 for j > 0 && !IsPathSeparator(path[j-1]) {
36 j--
37 }
38
39 if j > 1 {
40
41 err = MkdirAll(fixRootDirectory(path[:j-1]), perm)
42 if err != nil {
43 return err
44 }
45 }
46
47
48 err = Mkdir(path, perm)
49 if err != nil {
50
51
52 dir, err1 := Lstat(path)
53 if err1 == nil && dir.IsDir() {
54 return nil
55 }
56 return err
57 }
58 return nil
59 }
60
61
62
63
64
65
66 func RemoveAll(path string) error {
67 return removeAll(path)
68 }
69
70
71 func endsWithDot(path string) bool {
72 if path == "." {
73 return true
74 }
75 if len(path) >= 2 && path[len(path)-1] == '.' && IsPathSeparator(path[len(path)-2]) {
76 return true
77 }
78 return false
79 }
80
View as plain text