]> Cypherpunks repositories - gostls13.git/commitdiff
os: os.RemoveAll has to check for 2 error codes on Windows. ENOENT is not enough.
authorJaroslavas Počepko <jp@webmaster.ms>
Thu, 8 Sep 2011 07:27:41 +0000 (17:27 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 8 Sep 2011 07:27:41 +0000 (17:27 +1000)
os.Lstat can return ENOTDIR as well.

R=golang-dev, r, alex.brainman
CC=golang-dev, rsc
https://golang.org/cl/4984051

src/pkg/os/file_posix.go
src/pkg/os/file_windows.go
src/pkg/os/path.go
src/pkg/syscall/mkerrors_windows.sh
src/pkg/syscall/zerrors_windows.go

index 14ddd92c4abf59273de159ed54cf130a7f205d5b..ff8554bfc8f2133f75b5dc52c126ca2663f51ac0 100644 (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
index 0cdd2fdf65f9a057c48d0d20e102f1a012e2019a..a3f5b4459798e51ac7d21a29ff62fc62b3ef74aa 100644 (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
 }
 
index a8dfce3075227c2903245140435178cac7326b55..b190c51e6d7930bcc3809754fef444c35a4cef34 100644 (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
index af95edd001c297ba588cc013fb470ecaeab0c094..a76f250fda84e78f866f6d1b983c78ef2f60a369 100755 (executable)
@@ -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.
index ae4506fac009488f6c5c5f6700907562892bf199..799ed490a2d51a4f54cdfc0a1002b0e20926d9ac 100644 (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.