Commit 646401bd authored by Alex Brainman's avatar Alex Brainman

os: add check for ERROR_BAD_NETPATH in windows IsNotExist

Otherwise IsNotExist does not account for not existent servers and shares.

Fixes #12374

Change-Id: I37f6850198f91dcb02a4a917b793339d7e30e934
Reviewed-on: https://go-review.googlesource.com/14579Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c604f48d
......@@ -19,6 +19,8 @@ func isExist(err error) bool {
err == syscall.ERROR_FILE_EXISTS || err == ErrExist
}
const _ERROR_BAD_NETPATH = syscall.Errno(53)
func isNotExist(err error) bool {
switch pe := err.(type) {
case nil:
......@@ -29,6 +31,7 @@ func isNotExist(err error) bool {
err = pe.Err
}
return err == syscall.ERROR_FILE_NOT_FOUND ||
err == _ERROR_BAD_NETPATH ||
err == syscall.ERROR_PATH_NOT_FOUND || err == ErrNotExist
}
......
......@@ -126,3 +126,23 @@ func TestStartProcessAttr(t *testing.T) {
defer p.Wait()
t.Fatalf("StartProcess expected to fail, but succeeded.")
}
func TestShareNotExistError(t *testing.T) {
if testing.Short() {
t.Skip("slow test that uses network; skipping")
}
_, err := os.Stat(`\\no_such_server\no_such_share\no_such_file`)
if err == nil {
t.Fatal("stat succeeded, but expected to fail")
}
if !os.IsNotExist(err) {
t.Fatalf("os.Stat failed with %q, but os.IsNotExist(err) is false", err)
}
}
func TestBadNetPathError(t *testing.T) {
const ERROR_BAD_NETPATH = syscall.Errno(53)
if !os.IsNotExist(ERROR_BAD_NETPATH) {
t.Fatal("os.IsNotExist(syscall.Errno(53)) is false, but want true")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment