]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: handle "C:." correctly in EvalSymlinks on Windows
authorHiroshi Ioka <hirochachacha@gmail.com>
Fri, 26 Aug 2016 04:50:34 +0000 (13:50 +0900)
committerAlex Brainman <alex.brainman@gmail.com>
Mon, 5 Sep 2016 00:53:32 +0000 (00:53 +0000)
Fixes #16886

Change-Id: Idfacb0cf44d9994559c8e09032b4595887e76433
Reviewed-on: https://go-review.googlesource.com/28214
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/path/filepath/path_test.go
src/path/filepath/symlink.go

index e32922b4cc833d17d258e6af044606f1645ab524..737db6c93ac47eadbcc050c06e7a87832dcfe00d 100644 (file)
@@ -877,6 +877,40 @@ func TestEvalSymlinks(t *testing.T) {
                        t.Errorf(`EvalSymlinks(".") in %q directory returns %q, want "." or %q`, d.path, p, want)
                }()
 
+               // test EvalSymlinks("C:.") on Windows
+               if runtime.GOOS == "windows" {
+                       func() {
+                               defer func() {
+                                       err := os.Chdir(wd)
+                                       if err != nil {
+                                               t.Fatal(err)
+                                       }
+                               }()
+
+                               err := os.Chdir(path)
+                               if err != nil {
+                                       t.Error(err)
+                                       return
+                               }
+
+                               volDot := filepath.VolumeName(tmpDir) + "."
+
+                               p, err := filepath.EvalSymlinks(volDot)
+                               if err != nil {
+                                       t.Errorf(`EvalSymlinks("%s") in %q directory error: %v`, volDot, d.path, err)
+                                       return
+                               }
+                               if p == volDot {
+                                       return
+                               }
+                               want := filepath.Clean(findEvalSymlinksTestDirsDest(t, testdirs, d.path))
+                               if p == want {
+                                       return
+                               }
+                               t.Errorf(`EvalSymlinks("%s") in %q directory returns %q, want %q or %q`, volDot, d.path, p, volDot, want)
+                       }()
+               }
+
                // test EvalSymlinks(".."+path)
                func() {
                        defer func() {
index f627a94ddb90cf2585cab51d62688faa175bba47..824aee4e490564f7084842d8c15df81a51608522 100644 (file)
@@ -105,8 +105,9 @@ func walkSymlinks(path string) (string, error) {
                        // 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
+                       // Same for "C:.".
+                       if path[volumeNameLen(path):] == "." && !IsAbs(newpath) {
+                               return path, nil
                        }
                }
                if i == linksWalked {