Il giorno lunedì 11 dicembre 2017 19:08:01 UTC+1, Ian Lance Taylor ha scritto: > > On Mon, Dec 11, 2017 at 1:27 AM, Petr Shevtsov <petr.s...@gmail.com > <javascript:>> wrote: > > > > 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? > > This sounds like a bug, although it may not be easy to fix. Please > open an bug report at https://golang.org/issue. Thanks. > > I have opened the bug #23105.
See also #18974. Currently on UNIX systems isNotExist only checks for ENOENT, but what about ELOOP, ENAMETOOLONG and ENOTDIR? EACCESS and EOVERFLOW are more subtle, but probably the problem is trying to use os.IsNotExist after calling os.Stat to check if a file does not exist. To check if a file does not exist the correct way is, IMHO, to check if os.Stat returns an error; this is what Python os.path.exists do. Manlio -- 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.