diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2015-12-14 10:33:56 +1100 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-12-14 17:21:16 +0000 |
| commit | 61eb7058d0bd04fe4f616ddd011e0c0cb2eaa39d (patch) | |
| tree | 1efb88636a4d12cb3bc7c58a21b9de2aefc8f759 /src/path/filepath/symlink.go | |
| parent | cf49b35bd000279137c353fbdc9c02610b67be27 (diff) | |
| download | go-61eb7058d0bd04fe4f616ddd011e0c0cb2eaa39d.tar.xz | |
path/filepath: keep walking if EvalSymlinks returns symlink
Fixes #13582
Change-Id: I220f3c7b9511b3c080874f5c42f2a431fdddcbb7
Reviewed-on: https://go-review.googlesource.com/17794
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/path/filepath/symlink.go')
| -rw-r--r-- | src/path/filepath/symlink.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/path/filepath/symlink.go b/src/path/filepath/symlink.go index dc7e9eb9bf..bc287c5ecb 100644 --- a/src/path/filepath/symlink.go +++ b/src/path/filepath/symlink.go @@ -85,7 +85,6 @@ func walkLinks(path string, linksWalked *int) (string, error) { return newpath, nil } return Join(newdir, newpath), nil - } } @@ -94,9 +93,25 @@ func walkSymlinks(path string) (string, error) { return path, nil } var linksWalked int // to protect against cycles - newpath, err := walkLinks(path, &linksWalked) - if err != nil { - return "", err + for { + i := linksWalked + newpath, err := walkLinks(path, &linksWalked) + if err != nil { + return "", err + } + if runtime.GOOS == "windows" { + // walkLinks(".", ...) always retuns "." on unix. + // But on windows it returns symlink target, if current + // directory is a symlink. Stop the walk, if symlink + // target is not absolute path, and return "." + // to the caller (just like unix does). + if path == "." && !IsAbs(newpath) { + return ".", nil + } + } + if i == linksWalked { + return Clean(newpath), nil + } + path = newpath } - return Clean(newpath), nil } |
