From 6320236985d4c9c179b51dab2ea1ca4835123d49 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 9 Mar 2020 15:58:33 +0100 Subject: [PATCH] Partial revert of sys: windows: use golang.org/x/sys/windows - preserve `syscall.ENOTDIR` to match os.MkDirAll - change back parameter name to `adminAndLocalSystem` - revert accidental change of permissions of parent-dir Signed-off-by: Sebastiaan van Stijn --- sys/filesys_windows.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sys/filesys_windows.go b/sys/filesys_windows.go index 8c07ee7e8..2eaee2ca2 100644 --- a/sys/filesys_windows.go +++ b/sys/filesys_windows.go @@ -23,6 +23,7 @@ import ( "path/filepath" "regexp" "strings" + "syscall" "unsafe" "github.com/Microsoft/hcsshim" @@ -49,7 +50,7 @@ func MkdirAll(path string, _ os.FileMode) error { // mkdirall is a custom version of os.MkdirAll modified for use on Windows // so that it is both volume path aware, and can create a directory with // a DACL. -func mkdirall(path string, applyACL bool) error { +func mkdirall(path string, adminAndLocalSystem bool) error { if re := regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`); re.MatchString(path) { return nil } @@ -66,7 +67,7 @@ func mkdirall(path string, applyACL bool) error { return &os.PathError{ Op: "mkdir", Path: path, - Err: windows.ERROR_PATH_NOT_FOUND, + Err: syscall.ENOTDIR, } } @@ -83,14 +84,14 @@ func mkdirall(path string, applyACL bool) error { if j > 1 { // Create parent - err = mkdirall(path[0:j-1], false) + err = mkdirall(path[0:j-1], adminAndLocalSystem) if err != nil { return err } } // Parent now exists; invoke os.Mkdir or mkdirWithACL and use its result. - if applyACL { + if adminAndLocalSystem { err = mkdirWithACL(path) } else { err = os.Mkdir(path, 0) @@ -183,7 +184,7 @@ func OpenSequential(name string) (*os.File, error) { // If there is an error, it will be of type *PathError. func OpenFileSequential(name string, flag int, _ os.FileMode) (*os.File, error) { if name == "" { - return nil, &os.PathError{Op: "open", Path: name, Err: windows.ERROR_FILE_NOT_FOUND} + return nil, &os.PathError{Op: "open", Path: name, Err: syscall.ENOENT} } r, errf := windowsOpenFileSequential(name, flag, 0) if errf == nil {