pkg/system: synchronize mkdirall() with latest os.MkDirAll()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
2e66c0b6f0
commit
f058afc861
1 changed files with 15 additions and 8 deletions
|
@ -51,11 +51,7 @@ func mkdirall(path string, perm *windows.SecurityAttributes) error {
|
|||
if dir.IsDir() {
|
||||
return nil
|
||||
}
|
||||
return &os.PathError{
|
||||
Op: "mkdir",
|
||||
Path: path,
|
||||
Err: syscall.ENOTDIR,
|
||||
}
|
||||
return &os.PathError{Op: "mkdir", Path: path, Err: syscall.ENOTDIR}
|
||||
}
|
||||
|
||||
// Slow path: make sure parent exists and then call Mkdir for path.
|
||||
|
@ -70,14 +66,14 @@ func mkdirall(path string, perm *windows.SecurityAttributes) error {
|
|||
}
|
||||
|
||||
if j > 1 {
|
||||
// Create parent
|
||||
err = mkdirall(path[0:j-1], perm)
|
||||
// Create parent.
|
||||
err = mkdirall(fixRootDirectory(path[:j-1]), perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Parent now exists; invoke os.Mkdir or mkdirWithACL and use its result.
|
||||
// Parent now exists; invoke Mkdir and use its result.
|
||||
err = mkdirWithACL(path, perm)
|
||||
if err != nil {
|
||||
// Handle arguments like "foo/." by
|
||||
|
@ -115,6 +111,17 @@ func mkdirWithACL(name string, sa *windows.SecurityAttributes) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// fixRootDirectory fixes a reference to a drive's root directory to
|
||||
// have the required trailing slash.
|
||||
func fixRootDirectory(p string) string {
|
||||
if len(p) == len(`\\?\c:`) {
|
||||
if os.IsPathSeparator(p[0]) && os.IsPathSeparator(p[1]) && p[2] == '?' && os.IsPathSeparator(p[3]) && p[5] == ':' {
|
||||
return p + `\`
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func makeSecurityAttributes(sddl string) (*windows.SecurityAttributes, error) {
|
||||
var sa windows.SecurityAttributes
|
||||
sa.Length = uint32(unsafe.Sizeof(sa))
|
||||
|
|
Loading…
Add table
Reference in a new issue