]> Cypherpunks.ru repositories - gostls13.git/commit
net/http: improve handling of errors in Dir.Open
authorNathan Caza <mastercactapus@gmail.com>
Thu, 9 Feb 2017 00:42:52 +0000 (18:42 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 10 Feb 2017 01:59:27 +0000 (01:59 +0000)
commitee60d39a21f459b07cbc1550606db7ed231799e2
tree2a1010d5a1a31ba6adfc6ed2043f7343a5d0f513
parent866f63e84eb7096e64b7a39b993c2ca3e943e425
net/http: improve handling of errors in Dir.Open

The current implementation fails to produce an "IsNotExist" error on some
platforms (unix) for certain situations where it would be expected. This causes
downstream consumers, like FileServer, to emit 500 errors instead of a 404 for
some non-existant paths on certain platforms but not others.

As an example, os.Open("/index.html/foo") on a unix-type system will return
syscall.ENOTDIR, which os.IsNotExist cannot return true for (because the
error code is ambiguous without context). On windows, this same example
would result in os.IsNotExist returning true -- since the returned error is
specific.

This change alters Dir.Open to look up the tree for an "IsPermission" or
"IsNotExist" error to return, or a non-directory, returning os.ErrNotExist in
the last case. For all other error scenarios, the original error is returned.
This ensures that downstream code, like FileServer, receive errors that behave
the same across all platforms.

Fixes #18984

Change-Id: Id7d16591c24cd96afddb6d8ae135ac78da42ed37
Reviewed-on: https://go-review.googlesource.com/36635
Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/net/http/fs.go
src/net/http/fs_test.go