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

path/filepath: Windows Path Issue #66912

Closed
yasminvalim opened this issue Apr 18, 2024 · 2 comments
Closed

path/filepath: Windows Path Issue #66912

yasminvalim opened this issue Apr 18, 2024 · 2 comments

Comments

@yasminvalim
Copy link

Go version

1.21.0

Output of go env in your module/workspace:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ydesouza/.cache/go-build"
GOENV="/home/ydesouza/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ydesouza/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ydesouza/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.14"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ydesouza/workspace/rpms/ignition_project/github/fork/ignition/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3087023836=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Hey, I’m working on creating a validation that needs to handle paths, and as such I have started to leverage the package path/filepath, it works fine for linux and macos, however Windows seems to hang, regardless of the path we are validating (windows or linux). The function in question is

func Depth(path string) uint {
	var count uint = 0
	for p := filepath.Clean(path); p != "/" && p != "."; count++ {
		p = filepath.Dir(p)
	}
	return count
}

What did you see happen?

We are able to encourage a hang by simply putting this inside of a test function and letting CI run it.
Resulting in:

2m 39s
Run go test -timeout 120s -cover \
  
	github.com/coreos/ignition/v2/config/doc		coverage: 0.0% of statements
ok  	github.com/coreos/ignition/v2/config	1.160s	coverage: 17.6% of statements
?   	github.com/coreos/ignition/v2/config/shared	[no test files]
	github.com/coreos/ignition/v2/config/shared/parse		coverage: 0.0% of statements
	github.com/coreos/ignition/v2/config/shared/validations		coverage: 0.0% of statements
	github.com/coreos/ignition/v2/config/shared/errors		coverage: 0.0% of statements
?   	github.com/coreos/ignition/v2/config/translate/tests/pkga	[no test files]
?   	github.com/coreos/ignition/v2/config/translate/tests/pkgb	[no test files]
	github.com/coreos/ignition/v2/config/util		coverage: 0.0% of statements
ok  	github.com/coreos/ignition/v2/config/merge	1.184s	coverage: 69.3% of statements
ok  	github.com/coreos/ignition/v2/config/translate	1.151s	coverage: 45.2% of statements
ok  	github.com/coreos/ignition/v2/config/v3_0	1.182s	coverage: 41.9% of statements
ok  	github.com/coreos/ignition/v2/config/v3_0/types	1.159s	coverage: 52.7% of statements
ok  	github.com/coreos/ignition/v2/config/v3_1	1.181s	coverage: 49.0% of statements
ok  	github.com/coreos/ignition/v2/config/v3_1/translate	1.110s	coverage: 55.7% of statements
ok  	github.com/coreos/ignition/v2/config/v3_1/types	1.205s	coverage: 55.3% of statements
ok  	github.com/coreos/ignition/v2/config/v3_2	1.169s	coverage: 49.0% of statements
ok  	github.com/coreos/ignition/v2/config/v3_2/translate	1.137s	coverage: 55.3% of statements
ok  	github.com/coreos/ignition/v2/config/v3_2/types	1.142s	coverage: 51.1% of statements
ok  	github.com/coreos/ignition/v2/config/v3_3	1.188s	coverage: 49.0% of statements
ok  	github.com/coreos/ignition/v2/config/v3_3/translate	1.133s	coverage: 55.7% of statements
ok  	github.com/coreos/ignition/v2/config/v3_3/types	1.150s	coverage: 53.7% of statements
ok  	github.com/coreos/ignition/v2/config/v3_4	1.180s	coverage: 49.0% of statements
ok  	github.com/coreos/ignition/v2/config/v3_4/translate	1.153s	coverage: 49.5% of statements
ok  	github.com/coreos/ignition/v2/config/v3_4/types	1.192s	coverage: 57.0% of statements
ok  	github.com/coreos/ignition/v2/config/v3_5_experimental	1.214s	coverage: 49.0% of statements
ok  	github.com/coreos/ignition/v2/config/v3_5_experimental/translate	1.131s	coverage: 31.2% of statements
	github.com/coreos/ignition/v2/validate		coverage: 0.0% of statements
coverage: 2.6% of statements
panic: test timed out after 2m0s
running tests:
	TestDepthPath (2m0s)
goroutine 18 [running]:
testing.(*M).startAlarm.func1()
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:2366 +0x265
created by time.goFunc
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/time/sleep.go:177 +0x45
goroutine 1 [chan receive]:
testing.(*T).Run(0xc000120820, {0x140424bc9, 0xd}, 0x140450d90)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:1750 +0x851
testing.runTests.func1(0xc000120820)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:2161 +0x86
testing.tRunner(0xc000120820, 0xc000107b00)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:1689 +0x21f
testing.runTests(0xc000008180, {0x1403adc00, 0x20, 0x20}, {0xc000107ba8?, 0xc000107bf0?, 0x1406286a0?})
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:2159 +0x8bf
testing.(*M).Run(0xc000064f00)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:2027 +0xf18
main.main()
	_testmain.go:143 +0x2e5
goroutine 7 [runnable]:
strings.Replace({0xc00000b324, 0x0}, {0x140421e39, 0x1}, {0x1404a6688, 0x1}, 0xffffffffffffffff)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/strings/strings.go:1060 +0x3be
strings.ReplaceAll(...)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/strings/strings.go:1100
path/filepath.FromSlash(...)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/path/filepath/path.go:231
path/filepath.VolumeName({0xc00000b324, 0x1})
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/path/filepath/path.go:638 +0x6a
path/filepath.Dir({0xc00000b324, 0x1})
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/path/filepath/path.go:620 +0x35
github.com/coreos/ignition/v2/config/v3_5_experimental/types.TestDepthPath(0xc000120b60)
	D:/a/ignition/ignition/config/v3_5_experimental/types/config_test.go:353 +0x7e
testing.tRunner(0xc000120b60, 0x140450d90)
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:1689 +0x21f
created by testing.(*T).Run in goroutine 1
	C:/hostedtoolcache/windows/go/1.22.1/x64/src/testing/testing.go:1742 +0x826
FAIL	github.com/coreos/ignition/v2/config/v3_5_experimental/types	120.152s
ok  	github.com/coreos/ignition/v2/config/validate	1.108s	coverage: 46.8% of statements
FAIL

Do you have any ideas why this would get stuck on windows explicitly, we expect the IO interactions differ, but dont know enough about how windows works to know.

Do you have any ideas why this would get stuck on windows explicitly, we expect the IO interactions differ, but dont know enough about how windows works to know.

What did you expect to see?

I was expecting it to run it smoothly since Linux worked well. I also tried in differents Golang versions such1.22.1and 1.22.2.

@ArnoSen
Copy link

ArnoSen commented Apr 19, 2024

The documentation reads:

The returned path ends in a slash only if it represents a root directory, such as "/" on Unix or `C:\` on Windows. 
(...)
Finally, any occurrences of slash are replaced by Separator. 

I have not tested this but I guess this your function should be something like to work across OSes:

func Depth(path string) uint {
	var count uint = 0
	for p := filepath.Clean(path); p != filepath.Seperator && p != "."; count++ {
		p = filepath.Dir(p)
	}
	return count
}

@seankhliao seankhliao changed the title Windows Path Issue in package path/filepath path/filepath: Windows Path Issue Apr 19, 2024
@seankhliao
Copy link
Member

Windows doesn't have a root of /.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants