Commit eae11919 authored by Felix Lange's avatar Felix Lange

cmd/utils: fix path expansion on windows

parent 78b101e1
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/user" "os/user"
"path/filepath" "path"
"strings" "strings"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
...@@ -138,11 +138,8 @@ func (self *DirectoryFlag) Set(value string) { ...@@ -138,11 +138,8 @@ func (self *DirectoryFlag) Set(value string) {
func expandPath(p string) string { func expandPath(p string) string {
if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") { if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") {
if user, err := user.Current(); err == nil { if user, err := user.Current(); err == nil {
if err == nil { p = user.HomeDir + p[1:]
p = strings.Replace(p, "~", user.HomeDir, 1)
}
} }
} }
return path.Clean(os.ExpandEnv(p))
return filepath.Clean(os.ExpandEnv(p))
} }
...@@ -23,18 +23,15 @@ import ( ...@@ -23,18 +23,15 @@ import (
) )
func TestPathExpansion(t *testing.T) { func TestPathExpansion(t *testing.T) {
user, _ := user.Current() user, _ := user.Current()
tests := map[string]string{ tests := map[string]string{
"/home/someuser/tmp": "/home/someuser/tmp", "/home/someuser/tmp": "/home/someuser/tmp",
"~/tmp": user.HomeDir + "/tmp", "~/tmp": user.HomeDir + "/tmp",
"~thisOtherUser/b/": "~thisOtherUser/b",
"$DDDXXX/a/b": "/tmp/a/b", "$DDDXXX/a/b": "/tmp/a/b",
"/a/b/": "/a/b", "/a/b/": "/a/b",
} }
os.Setenv("DDDXXX", "/tmp") os.Setenv("DDDXXX", "/tmp")
for test, expected := range tests { for test, expected := range tests {
got := expandPath(test) got := expandPath(test)
if got != expected { if got != expected {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment