Skip to content
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: ReadDir returns ERROR_PATH_NOT_FOUND instead of ENOTDIR #46734

Open
codefromthecrypt opened this issue Jun 14, 2021 · 4 comments
Open

os: ReadDir returns ERROR_PATH_NOT_FOUND instead of ENOTDIR #46734

codefromthecrypt opened this issue Jun 14, 2021 · 4 comments

Comments

@codefromthecrypt
Copy link

@codefromthecrypt codefromthecrypt commented Jun 14, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.5 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\moo\AppData\Local\go-build
set GOENV=C:\Users\moo\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\moo\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\moo\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\moo\.gimme\versions\go1.16.5.windows.amd64
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\moo\.gimme\versions\go1.16.5.windows.amd64\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.5
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\moo\oss\getenvoy\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\moo\AppData\Local\Temp\go-build3391750208=/tmp/go-build -gno-record-gcc-switches

What did you do?

	files, err := os.ReadDir(filePath)

What did you expect to see?

err should be ENOTDIR

What did you see instead?

os.IsNotExist(err) matches because it was ERROR_PATH_NOT_FOUND

@codefromthecrypt
Copy link
Author

@codefromthecrypt codefromthecrypt commented Jun 14, 2021

the problem is here

if !file.isdir() {
the state check isn't valid for the call site

a lazy double-check like darwin is one way out, but up to you!

if f.dirinfo == nil {

@codefromthecrypt
Copy link
Author

@codefromthecrypt codefromthecrypt commented Jun 14, 2021

specifically, in windows isdir is only valid if the file was opened as a directory, which isn't the case when there was a file there https://github.com/golang/go/blob/master/src/os/file_windows.go#L102

@seankhliao seankhliao changed the title Windows os.ReadDir returns ERROR_PATH_NOT_FOUND instead of ENOTDIR os: ReadDir returns ERROR_PATH_NOT_FOUND instead of ENOTDIR Jun 14, 2021
@networkimprov
Copy link

@networkimprov networkimprov commented Jun 21, 2021

cc @alexbrainman @bcmills @zx2c4 @mattn

@dmitshur re incomplete triage

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jun 22, 2021

What did you do?

	files, err := os.ReadDir(filePath)

That is not enough to reproduce this issue.

@codefromthecrypt can you, please, provide complete program with steps to reproduce?

Thank you.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants