Skip to content

Commit

Permalink
cmd/utils: fix path expansion on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Aug 6, 2015
1 parent 78b101e commit eae1191
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
9 changes: 3 additions & 6 deletions cmd/utils/customflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"os"
"os/user"
"path/filepath"
"path"
"strings"

"github.com/codegangsta/cli"
Expand Down Expand Up @@ -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))
}
5 changes: 1 addition & 4 deletions cmd/utils/customflags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit eae1191

Please sign in to comment.