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: Rel is not returning an error for symlinks #66622

Closed
mfbx9da4 opened this issue Mar 31, 2024 · 1 comment
Closed

path/filepath: Rel is not returning an error for symlinks #66622

mfbx9da4 opened this issue Mar 31, 2024 · 1 comment

Comments

@mfbx9da4
Copy link

mfbx9da4 commented Mar 31, 2024

Go version

go version go1.22.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/da/Library/Caches/go-build'
GOENV='/Users/da/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/da/go/pkg/mod'
GONOPROXY='github.com/speakeasy-api/*'
GONOSUMDB='github.com/speakeasy-api/*'
GOOS='darwin'
GOPATH='/Users/da/go'
GOPRIVATE='github.com/speakeasy-api/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/da/code/speakeasy/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9w/3j0xt3p530d10gz0w8v926l00000gn/T/go-build564162317=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

filpath.Rel(`/tmp/foo`, `/Users/me/file.txt`) // returns ../../Users/me/file.txt

This returned value is broken as /tmp is actually a symlink. I would expect the method to return an error because the docs say "An error is returned if targpath can't be made relative to basepath"

lrwxr-xr-x@ 1 root  wheel    11B 29 Feb 04:05 /tmp -> private/tmp

What did you see happen?

See above

What did you expect to see?

See above

@mfbx9da4 mfbx9da4 changed the title path/filepath: Rel is not throwing an error for symlinks path/filepath: Rel is not returning an error for symlinks Mar 31, 2024
@adonovan
Copy link
Member

adonovan commented Mar 31, 2024

By design, Rel is a purely lexical operation. It doesn't interact with the file system, so it cannot tell nor does it care that some path segments are symbolic links. It fails only when called on arguments such as ("..", ".") or ("/a", "a"), where the answer would depend on os.Getwd, or ("C:\foo", "D:\bar"), as there is no relative path that spans Windows volumes.

So Rel is working as intended.

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

2 participants