-
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: 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>
ee60d39a