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: Stat() returns inconsistent error on Windows #29119

Open
Xjs opened this Issue Dec 6, 2018 · 8 comments

Comments

Projects
None yet
5 participants
@Xjs

Xjs commented Dec 6, 2018

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

$ go version
go version go1.11.1 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 GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\jannis.schnitzer\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:/Users/jannis.schnitzer
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
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 -fmessage-length=0 -fdebug-prefix-map=C:\tools\msys64\tmp\go-build255706334=/tmp/go-build -gno-record-gcc-switches

What did you do?

Execute the following program under Windows:

package main

import (
        "fmt"
        "os"
)

func main() {
        var err error
        _, err = os.Stat("doesnotexist")
        fmt.Println(err, os.IsNotExist(err))
        _, err = os.Stat("doesnotexist/")
        fmt.Println(err, os.IsNotExist(err))
        _, err = os.Stat("/doesnotexist")
        fmt.Println(err, os.IsNotExist(err))
        _, err = os.Stat("/doesnotexist/")
        fmt.Println(err, os.IsNotExist(err))
}

What did you expect to see?

All four lines should output the same error message. (Like on https://play.golang.org/p/X0RVDSjWRmi)

What did you see instead?

$ go run stat.go
FindFirstFile doesnotexist: The system cannot find the file specified. true
FindFirstFile doesnotexist/: The parameter is incorrect. false
FindFirstFile /doesnotexist: The system cannot find the file specified. true
FindFirstFile /doesnotexist/: The system cannot find the path specified. true

The second line (os.Stat("doesnotexist/")) produces a different error. Particularly os.IsNotExist(os.Stat("relative_path_that_doesnt_exist_and_ends_in_a_slash/")) is unexpectedly false.

Linux and macOS behave as expected.

@tklauser tklauser added the OS-Windows label Dec 6, 2018

@tklauser

This comment has been minimized.

Member

tklauser commented Dec 6, 2018

@cgopalan

This comment has been minimized.

cgopalan commented Dec 6, 2018

FYI This does not happen in version 1.10.3

λ go version
go version go1.10.3 windows/amd64
λ go run teststat.go
CreateFile doesnotexist: The system cannot find the file specified. true
CreateFile doesnotexist/: The system cannot find the file specified. true
CreateFile /doesnotexist: The system cannot find the file specified. true
CreateFile /doesnotexist/: The system cannot find the file specified. true
@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Dec 7, 2018

FYI This does not happen in version 1.10.3

This does not happen on the tip either (I am using 9be01c2)

C:\>u:\test
CreateFile doesnotexist: The system cannot find the file specified. true
CreateFile doesnotexist/: The system cannot find the file specified. true
CreateFile /doesnotexist: The system cannot find the file specified. true
CreateFile /doesnotexist/: The system cannot find the file specified. true

C:\>

Alex

@cgopalan

This comment has been minimized.

cgopalan commented Dec 9, 2018

@alexbrainman I just saw that the test i wrote failed. So this is not an issue in the latest master but was only an issue in the 1.11 release?
FYI I did test on the latest go release which I downloaded and I did get the error.

@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Dec 9, 2018

@alexbrainman I just saw that the test i wrote failed. So this is not an issue in the latest master but was only an issue in the 1.11 release?

This issues does exists in go1.11. But, I believe, it has been fixed on current tip.

Alex

@cgopalan

This comment has been minimized.

cgopalan commented Dec 9, 2018

@alexbrainman oh so should I just close the PR?

@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Dec 9, 2018

@alexbrainman oh so should I just close the PR?

I think your PR is not need. There is no problem here to fix.

Alex

@cgopalan

This comment has been minimized.

cgopalan commented Dec 9, 2018

@alexbrainman ok will close it then. @Xjs seems like this is fixed in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment