]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: convert drive letter to upper case in windows EvalSymlinks
authorAlex Brainman <alex.brainman@gmail.com>
Tue, 27 Mar 2012 01:56:56 +0000 (12:56 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Tue, 27 Mar 2012 01:56:56 +0000 (12:56 +1100)
Fixes #3347.

R=golang-dev, aram, r, rsc
CC=golang-dev
https://golang.org/cl/5918043

src/pkg/path/filepath/path_test.go
src/pkg/path/filepath/symlink_windows.go

index 2aba553d23efb274e3a4d5fc8eb36d21777768f7..b8766588cf5937d091b6facc8ebd656442e8a156 100644 (file)
@@ -846,3 +846,26 @@ func TestVolumeName(t *testing.T) {
                }
        }
 }
+
+func TestDriveLetterInEvalSymlinks(t *testing.T) {
+       if runtime.GOOS != "windows" {
+               return
+       }
+       wd, _ := os.Getwd()
+       if len(wd) < 3 {
+               t.Errorf("Current directory path %q is too short", wd)
+       }
+       lp := strings.ToLower(wd)
+       up := strings.ToUpper(wd)
+       flp, err := filepath.EvalSymlinks(lp)
+       if err != nil {
+               t.Fatalf("EvalSymlinks(%q) failed: %q", lp, err)
+       }
+       fup, err := filepath.EvalSymlinks(up)
+       if err != nil {
+               t.Fatalf("EvalSymlinks(%q) failed: %q", up, err)
+       }
+       if flp != fup {
+               t.Errorf("Results of EvalSymlinks do not match: %q and %q", flp, fup)
+       }
+}
index afa88bfe876f1ea1dca7f8af50617305e70728e0..2d4257720e000989d2bb6292c059b4aeafe454e0 100644 (file)
@@ -23,5 +23,13 @@ func evalSymlinks(path string) (string, error) {
                }
        }
        b = b[:n]
-       return Clean(syscall.UTF16ToString(b)), nil
+       s := syscall.UTF16ToString(b)
+       // syscall.GetLongPathName does not change the case of the drive letter,
+       // but the result of EvalSymlinks must be unique, so we have
+       // EvalSymlinks(`c:\a`) == EvalSymlinks(`C:\a`).
+       // Make drive letter upper case. This matches what os.Getwd returns.
+       if len(s) >= 2 && s[1] == ':' && 'a' <= s[0] && s[0] <= 'z' {
+               s = string(s[0]+'A'-'a') + s[1:]
+       }
+       return Clean(s), nil
 }