• Nathan Caza's avatar
    net/http: improve handling of errors in Dir.Open · ee60d39a
    Nathan Caza authored
    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/36635Reviewed-by: 's avatarYasuhiro MATSUMOTO <mattn.jp@gmail.com>
    Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    ee60d39a
Name
Last commit
Last update
..
cgi Loading commit data...
cookiejar Loading commit data...
fcgi Loading commit data...
httptest Loading commit data...
httptrace Loading commit data...
httputil Loading commit data...
internal Loading commit data...
pprof Loading commit data...
testdata Loading commit data...
client.go Loading commit data...
client_test.go Loading commit data...
clientserver_test.go Loading commit data...
cookie.go Loading commit data...
cookie_test.go Loading commit data...
doc.go Loading commit data...
example_test.go Loading commit data...
export_test.go Loading commit data...
filetransport.go Loading commit data...
filetransport_test.go Loading commit data...
fs.go Loading commit data...
fs_test.go Loading commit data...
h2_bundle.go Loading commit data...
header.go Loading commit data...
header_test.go Loading commit data...
http.go Loading commit data...
http_test.go Loading commit data...
jar.go Loading commit data...
main_test.go Loading commit data...
method.go Loading commit data...
npn_test.go Loading commit data...
proxy_test.go Loading commit data...
race.go Loading commit data...
range_test.go Loading commit data...
readrequest_test.go Loading commit data...
request.go Loading commit data...
request_test.go Loading commit data...
requestwrite_test.go Loading commit data...
response.go Loading commit data...
response_test.go Loading commit data...
responsewrite_test.go Loading commit data...
serve_test.go Loading commit data...
server.go Loading commit data...
sniff.go Loading commit data...
sniff_test.go Loading commit data...
status.go Loading commit data...
transfer.go Loading commit data...
transfer_test.go Loading commit data...
transport.go Loading commit data...
transport_internal_test.go Loading commit data...
transport_test.go Loading commit data...
triv.go Loading commit data...