mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07:00
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/14579 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
c604f48d24
commit
646401bdf0
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user