1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:24:40 -07:00

os: os.RemoveAll has to check for 2 error codes on Windows. ENOENT is not enough.

os.Lstat can return ENOTDIR as well.

R=golang-dev, r, alex.brainman
CC=golang-dev, rsc
https://golang.org/cl/4984051
This commit is contained in:
Jaroslavas Počepko 2011-09-08 17:27:41 +10:00 committed by Alex Brainman
parent bb8bbb2908
commit 571d3f50d3
5 changed files with 4 additions and 13 deletions

View File

@ -46,7 +46,7 @@ func Remove(name string) Error {
// both errors will be ENOTDIR, so it's okay to
// use the error from unlink.
// For windows syscall.ENOTDIR is set
// to syscall.ERROR_DIRECTORY, hopefully it should
// to syscall.ERROR_PATH_NOT_FOUND, hopefully it should
// do the trick.
if e1 != syscall.ENOTDIR {
e = e1

View File

@ -92,15 +92,6 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err Error) {
if e == nil {
return r, nil
}
// Imitating Unix behavior by replacing syscall.ERROR_PATH_NOT_FOUND with
// os.ENOTDIR. Not sure if we should go into that.
if e2, ok := e.(*PathError); ok {
if e3, ok := e2.Error.(Errno); ok {
if e3 == Errno(syscall.ERROR_PATH_NOT_FOUND) {
return nil, &PathError{"open", name, ENOTDIR}
}
}
}
return nil, e
}

View File

@ -68,7 +68,7 @@ func RemoveAll(path string) Error {
// Otherwise, is this a directory we need to recurse into?
dir, serr := Lstat(path)
if serr != nil {
if serr, ok := serr.(*PathError); ok && serr.Error == ENOENT {
if serr, ok := serr.(*PathError); ok && (serr.Error == ENOENT || serr.Error == ENOTDIR) {
return nil
}
return serr

View File

@ -76,7 +76,7 @@ done
# These are go errors that will be mapped directly to windows errors
goerrors='
ENOENT:ERROR_FILE_NOT_FOUND
ENOTDIR:ERROR_DIRECTORY
ENOTDIR:ERROR_PATH_NOT_FOUND
'
# Pull out just the error names for later.

View File

@ -6,7 +6,7 @@ package syscall
// Go names for Windows errors.
const (
ENOENT = ERROR_FILE_NOT_FOUND
ENOTDIR = ERROR_DIRECTORY
ENOTDIR = ERROR_PATH_NOT_FOUND
)
// Windows reserves errors >= 1<<29 for application use.