Merge pull request #4095 from thaJeztah/partial_revert

Partial revert of sys: windows: use golang.org/x/sys/windows
This commit is contained in:
Michael Crosby 2020-03-09 14:43:33 -04:00 committed by GitHub
commit 4eb9d15dc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"syscall"
"unsafe" "unsafe"
"github.com/Microsoft/hcsshim" "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 // 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 // so that it is both volume path aware, and can create a directory with
// a DACL. // 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) { if re := regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`); re.MatchString(path) {
return nil return nil
} }
@ -66,7 +67,7 @@ func mkdirall(path string, applyACL bool) error {
return &os.PathError{ return &os.PathError{
Op: "mkdir", Op: "mkdir",
Path: path, 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 { if j > 1 {
// Create parent // Create parent
err = mkdirall(path[0:j-1], false) err = mkdirall(path[0:j-1], adminAndLocalSystem)
if err != nil { if err != nil {
return err return err
} }
} }
// Parent now exists; invoke os.Mkdir or mkdirWithACL and use its result. // Parent now exists; invoke os.Mkdir or mkdirWithACL and use its result.
if applyACL { if adminAndLocalSystem {
err = mkdirWithACL(path) err = mkdirWithACL(path)
} else { } else {
err = os.Mkdir(path, 0) 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. // If there is an error, it will be of type *PathError.
func OpenFileSequential(name string, flag int, _ os.FileMode) (*os.File, error) { func OpenFileSequential(name string, flag int, _ os.FileMode) (*os.File, error) {
if name == "" { 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) r, errf := windowsOpenFileSequential(name, flag, 0)
if errf == nil { if errf == nil {