os: make tests work on windows
Fixes #1105.
R=golang-dev, r
CC=Joe Poirier, golang-dev
https://golang.org/cl/2343043
diff --git a/src/pkg/os/file_windows.go b/src/pkg/os/file_windows.go
index cee3aad..d5978a8 100644
--- a/src/pkg/os/file_windows.go
+++ b/src/pkg/os/file_windows.go
@@ -53,12 +53,25 @@
// TODO(brainman): not sure about my logic of assuming it is dir first, then fall back to file
r, e := openDir(name)
if e == nil {
+ if flag&O_WRONLY != 0 || flag&O_RDWR != 0 {
+ r.Close()
+ return nil, &PathError{"open", name, EISDIR}
+ }
return r, nil
}
r, e = openFile(name, flag, perm)
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
}