Skip to content

Commit

Permalink
cmd/go: make sure that the RelPaths always returns valid paths
Browse files Browse the repository at this point in the history
When dealing with symlinks, filepath.Rel does not always return a valid path
as described in golang#30336

This change makes sure that the shorter path is not used if it isn't valid.

Fixes golang#30336
  • Loading branch information
zegl committed Mar 2, 2019
1 parent 337a1bd commit fb6bfa4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cmd/go/internal/base/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func RelPaths(paths []string) []string {
for _, p := range paths {
rel, err := filepath.Rel(pwd, p)
if err == nil && len(rel) < len(p) {
p = rel
// Verify that the shorter path is a valid path. This is not the
// case if pwd is in a symlink as p is set to the realpath, not the
// relative path seen from pwd.
if _, err := os.Stat(rel); err == nil {
p = rel
}
}
out = append(out, p)
}
Expand Down

0 comments on commit fb6bfa4

Please sign in to comment.