You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
calling filepath.Abs returns different values based on whether the program is ran in terminal or in CI/CD system because it sometimes uses Getenv("PWD") OR does syscall.Getwd
The way it works is that if the environment variable PWD is set, and it names the same directory as the current directory, then we use the value in PWD. This generally gives a better result when using a Unix shell. If PWD is not set, then we call the getcwd system call. If you need some sort of canonicalized path that is independent of PWD, use filepath.EvalSymlinks.
I already worked around it by evaluating the symlinks but I wouldn't call this "working as intended."
having the api rely on both PWD and getcwd is wrong. os.Chdir doesn't change PWD and vice-versa. Which is fine.
The API should pick one lookup method though.
Instead we had a program that passes the test suite but failed in production because the golang API used the PWD environment variable in production and getcwd in the test suite.
I don't agree that there is an obvious right answer here. The approach that Go takes is the one that most Unix shells take, and it produces appropriate results when a user uses cd to get to a directory and then runs a Go program that uses that directory.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
calling
filepath.Abs
returns different values based on whether the program is ran in terminal or in CI/CD system because it sometimes uses Getenv("PWD") OR does syscall.Getwdhttps://play.golang.org/p/lvU1dF0dFcE
What did you expect to see?
I expect the filepath.Abs to return the same value and be consistent and either always call syscall.Getwd or always use PWD
What did you see instead?
Different values. View https://play.golang.org/p/lvU1dF0dFcE example
The text was updated successfully, but these errors were encountered: