From eae1191904fd739cdffdd2903509a44a35c4c2f2 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 6 Aug 2015 15:18:32 +0100 Subject: [PATCH] cmd/utils: fix path expansion on windows --- cmd/utils/customflags.go | 9 +++------ cmd/utils/customflags_test.go | 5 +---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/cmd/utils/customflags.go b/cmd/utils/customflags.go index e7efed4e3c..4450065c14 100644 --- a/cmd/utils/customflags.go +++ b/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)) } diff --git a/cmd/utils/customflags_test.go b/cmd/utils/customflags_test.go index 0fb0af63b7..de39ca36a1 100644 --- a/cmd/utils/customflags_test.go +++ b/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 {