Browse Source

cmd/utils: fix path expansion on windows

Felix Lange 10 years ago
parent
commit
eae1191904
2 changed files with 4 additions and 10 deletions
  1. 3 6
      cmd/utils/customflags.go
  2. 1 4
      cmd/utils/customflags_test.go

+ 3 - 6
cmd/utils/customflags.go

@@ -21,7 +21,7 @@ import (
 	"fmt"
 	"os"
 	"os/user"
-	"path/filepath"
+	"path"
 	"strings"
 
 	"github.com/codegangsta/cli"
@@ -138,11 +138,8 @@ func (self *DirectoryFlag) Set(value string) {
 func expandPath(p string) string {
 	if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") {
 		if user, err := user.Current(); err == nil {
-			if err == nil {
-				p = strings.Replace(p, "~", user.HomeDir, 1)
-			}
+			p = user.HomeDir + p[1:]
 		}
 	}
-
-	return filepath.Clean(os.ExpandEnv(p))
+	return path.Clean(os.ExpandEnv(p))
 }

+ 1 - 4
cmd/utils/customflags_test.go

@@ -23,18 +23,15 @@ import (
 )
 
 func TestPathExpansion(t *testing.T) {
-
 	user, _ := user.Current()
-
 	tests := map[string]string{
 		"/home/someuser/tmp": "/home/someuser/tmp",
 		"~/tmp":              user.HomeDir + "/tmp",
+		"~thisOtherUser/b/":  "~thisOtherUser/b",
 		"$DDDXXX/a/b":        "/tmp/a/b",
 		"/a/b/":              "/a/b",
 	}
-
 	os.Setenv("DDDXXX", "/tmp")
-
 	for test, expected := range tests {
 		got := expandPath(test)
 		if got != expected {