Greetings, gophers!

I've spotted rather strange behavior of os.IsNotExist on Windows.

This snippet[1]

s := "http://example.com/";
fi, err := os.Stat(s)
if os.IsNotExist(err) {
fmt.Println("Not a file")
return
}
mode := fi.Mode()
if mode.IsRegular() {
fmt.Println("File")
}

works perfectly on Linux but panics on Windows.

This happens because of os.Stat returns an error "CreateFile 
http://example.com/: The filename, directory name, or volume label syntax 
is incorrect." (errno 123[2]) for such input, but os.IsNotExist(err) 
returns false.

Is this a bug in os.IsNotExist[3] or such behavior is intentional?


[1] https://play.golang.org/p/oC-ecJLBso
[2] 
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx#error_invalid_name
[3] actually in isNotExit function in os/error_windows.go

--
Petr Shevtsov

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to