]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: make Abs handle paths like c:a.txt properly
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 22 Aug 2014 07:14:42 +0000 (17:14 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Fri, 22 Aug 2014 07:14:42 +0000 (17:14 +1000)
Fixes #8145.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/126440043

src/pkg/path/filepath/path.go
src/pkg/path/filepath/path_plan9.go
src/pkg/path/filepath/path_test.go
src/pkg/path/filepath/path_unix.go
src/pkg/path/filepath/path_windows.go

index 71603cc5946ade3dd91dfc2aa4cb90e4b6cab23b..7fa3b9b56a9d66c683c33efd8fcf95aaca2a3d8c 100644 (file)
@@ -231,6 +231,10 @@ func EvalSymlinks(path string) (string, error) {
 // working directory to turn it into an absolute path.  The absolute
 // path name for a given file is not guaranteed to be unique.
 func Abs(path string) (string, error) {
+       return abs(path)
+}
+
+func unixAbs(path string) (string, error) {
        if IsAbs(path) {
                return Clean(path), nil
        }
index 12e85aae00c8de51e5dbefa9705db724dcbb1572..ee8912d58e1dbbcf9d19ccf278092d988ae2a1f0 100644 (file)
@@ -28,3 +28,7 @@ func splitList(path string) []string {
        }
        return strings.Split(path, string(ListSeparator))
 }
+
+func abs(path string) (string, error) {
+       return unixAbs(path)
+}
index 8cdc763f1b51c422c5bba7d309b43c87dbfd2eb8..399284b97da310e70247bc35e478d468b1b02d50 100644 (file)
@@ -628,6 +628,8 @@ var winisabstests = []IsAbsTest{
        {`\`, false},
        {`\Windows`, false},
        {`c:a\b`, false},
+       {`c:\a\b`, true},
+       {`c:/a/b`, true},
        {`\\host\share\foo`, true},
        {`//host/share/foo/bar`, true},
 }
@@ -807,6 +809,19 @@ func TestAbs(t *testing.T) {
                }
        }
 
+       if runtime.GOOS == "windows" {
+               vol := filepath.VolumeName(root)
+               var extra []string
+               for _, path := range absTests {
+                       if strings.Index(path, "$") != -1 {
+                               continue
+                       }
+                       path = vol + path
+                       extra = append(extra, path)
+               }
+               absTests = append(absTests, extra...)
+       }
+
        err = os.Chdir(absTestDirs[0])
        if err != nil {
                t.Fatal("chdir failed: ", err)
index 7aba0ab5b9bb2e09488612c8236a91859c0157ef..4e7d0d1b42258e57f6125efc9219b89a1e63f6fc 100644 (file)
@@ -30,3 +30,7 @@ func splitList(path string) []string {
        }
        return strings.Split(path, string(ListSeparator))
 }
+
+func abs(path string) (string, error) {
+       return unixAbs(path)
+}
index e99997257d75602a18535d21e17ac790f0d07d3e..ec50f6b264f3b304f4edf281caca0a37b55fdb74 100644 (file)
@@ -6,6 +6,7 @@ package filepath
 
 import (
        "strings"
+       "syscall"
 )
 
 func isSlash(c uint8) bool {
@@ -103,3 +104,7 @@ func splitList(path string) []string {
 
        return list
 }
+
+func abs(path string) (string, error) {
+       return syscall.FullPath(path)
+}