Skip to content

Commit f058afc

Browse files
committed
pkg/system: synchronize mkdirall() with latest os.MkDirAll()
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 2e66c0b commit f058afc

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

pkg/system/filesys_windows.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ func mkdirall(path string, perm *windows.SecurityAttributes) error {
5151
if dir.IsDir() {
5252
return nil
5353
}
54-
return &os.PathError{
55-
Op: "mkdir",
56-
Path: path,
57-
Err: syscall.ENOTDIR,
58-
}
54+
return &os.PathError{Op: "mkdir", Path: path, Err: syscall.ENOTDIR}
5955
}
6056

6157
// Slow path: make sure parent exists and then call Mkdir for path.
@@ -70,14 +66,14 @@ func mkdirall(path string, perm *windows.SecurityAttributes) error {
7066
}
7167

7268
if j > 1 {
73-
// Create parent
74-
err = mkdirall(path[0:j-1], perm)
69+
// Create parent.
70+
err = mkdirall(fixRootDirectory(path[:j-1]), perm)
7571
if err != nil {
7672
return err
7773
}
7874
}
7975

80-
// Parent now exists; invoke os.Mkdir or mkdirWithACL and use its result.
76+
// Parent now exists; invoke Mkdir and use its result.
8177
err = mkdirWithACL(path, perm)
8278
if err != nil {
8379
// Handle arguments like "foo/." by
@@ -115,6 +111,17 @@ func mkdirWithACL(name string, sa *windows.SecurityAttributes) error {
115111
return nil
116112
}
117113

114+
// fixRootDirectory fixes a reference to a drive's root directory to
115+
// have the required trailing slash.
116+
func fixRootDirectory(p string) string {
117+
if len(p) == len(`\\?\c:`) {
118+
if os.IsPathSeparator(p[0]) && os.IsPathSeparator(p[1]) && p[2] == '?' && os.IsPathSeparator(p[3]) && p[5] == ':' {
119+
return p + `\`
120+
}
121+
}
122+
return p
123+
}
124+
118125
func makeSecurityAttributes(sddl string) (*windows.SecurityAttributes, error) {
119126
var sa windows.SecurityAttributes
120127
sa.Length = uint32(unsafe.Sizeof(sa))

0 commit comments

Comments
 (0)