-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: IsNotExist returns false for syscall.ENOTDIR #18974
Comments
@ianlancetaylor, thoughts on whether syscall.ENOTDIR should be an os.IsNotExist? |
@bradfitz on decision whether this should be handled, mind if I submit the code review? I am looking to get into contributing to go |
@Ichbinjoe, if you'd like, but it might be better to wait for a decision so you don't waste any time. |
Unfortunately I don't think that
This will set Closing. |
Ah, you're right. Context is important in this case, caller's of It might be worthwhile to add something to the docs to clarify that the caller should take care to understand those implications. In file-access-type usages (like the http.FileServer) os.IsNotExist is not enough to determine if a not-found error should be returned -- but it seems to be common practice to do so. I'll open a separate issue for the FileServer behavior. |
@ianlancetaylor I was working on a fix for the FileServer, and I came across some new light on this that I'd like to get your opinion on. It would seem this behavior actually differs from platform to platform, and may be worth fixing in the With regards to "non-existant.file" and "non-existant.file/path": On windows, ERROR_PATH_NOT_FOUND is returned instead of ERROR_FILE_NOT_FOUND (two separate errors), though both are reported as But with the same code & file structure on a unix system, os.IsNotExist returns With the readdir example, I found that the errors are distinguishable too, so it should be solvable. // os.Open
&os.PathError{Op:"open", Path:"test.go/foo", Err:0x14}
// fd.Readdir
&os.SyscallError{Syscall:"readdirent", Err:0x14} If the And I think it would be valid to consider resolving this within the os package. A precise fix for this in Let me know what your thoughts are on this. |
It's impossible for the os package to fully handle all cases identically across operating systems. I don't think we want to add the complexity of having For example, I can get the exact error you show by calling |
Darn, I hadn't considered that. Thank you for taking the time to comment back on this, your insight was very helpful! |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7.5 and 1.8rc3
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nathan/projects"
GORACE=""
GOROOT="/Users/nathan/go"
GOTOOLDIR="/Users/nathan/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mg/sm3pzxbx1n93_2jzksr2clwm0000gp/T/go-build206309359=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
Basic
IsNotExist
example: https://play.golang.org/p/mIvdT6IBHCHTTP example: https://play.golang.org/p/y_wAm3nZpq
What did you expect to see?
What did you see instead?
From the docs (and inferred from it's usage in stdlib)
"IsNotExist returns a boolean indicating whether the error is known to report that a file or directory does not exist. "
In this case, can we safely assume the "not a directory" error reports that the path does not exist?
The text was updated successfully, but these errors were encountered: