Skip to content

Commit 9488741

Browse files
kevparrasky
authored andcommitted
path/filepath: allow EvalSymlinks to work on UNC share roots on Windows
Fixes #42079 Previously, EvalSymlinks returned an error when called with the root of a UNC share (e.g. \\server\share). This was due to Windows's FindFirstFile function not supporting a share root path. To resolve this, now return early from toNorm in the case where the path after the volume name is empty. Skipping the later path component resolution shouldn't have any negative impact in this case, as if the path is empty, there aren't any path components to resolve anyways. The test case uses the localhost admin share (c$), as it should be present in most situations. This allows testing without setting up an external file share. However, this fix applies to all UNC share root paths. Change-Id: I05035bd86be93662d7bea34fab4b75fc8e918206 GitHub-Last-Rev: bd3db2c GitHub-Pull-Request: #42096 Reviewed-on: https://go-review.googlesource.com/c/go/+/263917 Trust: Alex Brainman <[email protected]> Trust: Giovanni Bajo <[email protected]> Run-TryBot: Alex Brainman <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent 7930d39 commit 9488741

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/path/filepath/path_windows_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ func TestToNorm(t *testing.T) {
413413
{`{{tmp}}\test`, `.\foo\bar`, `foo\bar`},
414414
{`{{tmp}}\test`, `foo\..\foo\bar`, `foo\bar`},
415415
{`{{tmp}}\test`, `FOO\BAR`, `foo\bar`},
416+
417+
// test UNC paths
418+
{".", `\\localhost\c$`, `\\localhost\c$`},
416419
}
417420

418421
tmp, err := ioutil.TempDir("", "testToNorm")

src/path/filepath/symlink_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func toNorm(path string, normBase func(string) (string, error)) (string, error)
6868
path = path[len(volume):]
6969

7070
// skip special cases
71-
if path == "." || path == `\` {
71+
if path == "" || path == "." || path == `\` {
7272
return volume + path, nil
7373
}
7474

0 commit comments

Comments
 (0)