]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: allow EvalSymlinks to work on UNC share roots on Windows
authorKevin Parsons <kevpar@microsoft.com>
Tue, 20 Oct 2020 15:15:23 +0000 (15:15 +0000)
committerGiovanni Bajo <rasky@develer.com>
Sun, 25 Oct 2020 07:51:58 +0000 (07:51 +0000)
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: bd3db2cda65aae1cdf8d94b03bc7197dff68dc44
GitHub-Pull-Request: golang/go#42096
Reviewed-on: https://go-review.googlesource.com/c/go/+/263917
Trust: Alex Brainman <alex.brainman@gmail.com>
Trust: Giovanni Bajo <rasky@develer.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/path/filepath/path_windows_test.go
src/path/filepath/symlink_windows.go

index 990f18614d7e76714c8d0d2d0d3743a6fe763fff..9309a7dc4dd5c0b709dee05c3ad48cb00a288c28 100644 (file)
@@ -413,6 +413,9 @@ func TestToNorm(t *testing.T) {
                {`{{tmp}}\test`, `.\foo\bar`, `foo\bar`},
                {`{{tmp}}\test`, `foo\..\foo\bar`, `foo\bar`},
                {`{{tmp}}\test`, `FOO\BAR`, `foo\bar`},
+
+               // test UNC paths
+               {".", `\\localhost\c$`, `\\localhost\c$`},
        }
 
        tmp, err := ioutil.TempDir("", "testToNorm")
index a799488c1824019363d64c0bbd87a11244157be8..d72279e2bbc1a468512d62be76d3fdb240c15b1a 100644 (file)
@@ -68,7 +68,7 @@ func toNorm(path string, normBase func(string) (string, error)) (string, error)
        path = path[len(volume):]
 
        // skip special cases
-       if path == "." || path == `\` {
+       if path == "" || path == "." || path == `\` {
                return volume + path, nil
        }