Skip to content

Commit 9f59918

Browse files
path/filepath: correct symlink eval for symlink at root
For a relative symlink in the root directory, such as /tmp -> private/tmp, we were dropping the leading slash. No test because we can't create a symlink in the root directory. The test TestGZIPFilesHaveZeroMTimes was failing on the Darwin builders. Updates #19922 Updates #20506 Change-Id: Ic83cb6d97ad0cb628fc551ac772a44fb3e20f038 Reviewed-on: https://go-review.googlesource.com/135295 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 7c95703 commit 9f59918

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/path/filepath/symlink.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ func walkSymlinks(path string) (string, error) {
4141
continue
4242
} else if path[start:end] == ".." {
4343
// Back up to previous component if possible.
44+
// Note that volLen includes any leading slash.
4445
var r int
45-
for r = len(dest) - 1; r >= 0; r-- {
46+
for r = len(dest) - 1; r >= volLen; r-- {
4647
if os.IsPathSeparator(dest[r]) {
4748
break
4849
}
4950
}
50-
if r < 0 {
51-
if len(dest) > 0 {
51+
if r < volLen {
52+
if len(dest) > volLen {
5253
dest += string(os.PathSeparator)
5354
}
5455
dest += ".."
@@ -117,12 +118,12 @@ func walkSymlinks(path string) (string, error) {
117118
// Symlink to relative path; replace last
118119
// path component in dest.
119120
var r int
120-
for r = len(dest) - 1; r >= 0; r-- {
121+
for r = len(dest) - 1; r >= volLen; r-- {
121122
if os.IsPathSeparator(dest[r]) {
122123
break
123124
}
124125
}
125-
if r < 0 {
126+
if r < volLen {
126127
dest = vol
127128
} else {
128129
dest = dest[:r]

0 commit comments

Comments
 (0)