From a60713514053225fc4878c860a1e621cdc739596 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Fri, 22 Jun 2018 16:49:54 -0600 Subject: [PATCH 1/3] Avoid conflict between binary location and workspace Don't try to create the workspace directory on top of the binary, if the binary happens to be downloaded to the default workspace directory. --- cmd/configure.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/configure.go b/cmd/configure.go index e143d49e5..34a718193 100644 --- a/cmd/configure.go +++ b/cmd/configure.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "path" "text/tabwriter" @@ -35,7 +36,14 @@ You can also override certain default settings to suit your preferences. return err } if usrCfg.Workspace == "" { - usrCfg.Workspace = path.Join(usrCfg.Home, path.Base(BinaryName)) + dirName := path.Base(BinaryName) + defaultWorkspace := path.Join(usrCfg.Home, dirName) + _, err := os.Stat(defaultWorkspace) + // Sorry about the double negative. + if !os.IsNotExist(err) { + defaultWorkspace = fmt.Sprintf("%s-1", defaultWorkspace) + } + usrCfg.Workspace = defaultWorkspace } apiCfg := config.NewEmptyAPIConfig() From 5bbf9363662ae1dcfe58aab417692ca810d464e4 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Fri, 22 Jun 2018 16:50:59 -0600 Subject: [PATCH 2/3] Place default workspace in home directory The default config had an empty string as Home, this writes Home first, so that the workspace goes there instead of in the current directory. --- cmd/configure.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/configure.go b/cmd/configure.go index 34a718193..a9f392371 100644 --- a/cmd/configure.go +++ b/cmd/configure.go @@ -35,6 +35,7 @@ You can also override certain default settings to suit your preferences. if err != nil { return err } + usrCfg.Normalize() if usrCfg.Workspace == "" { dirName := path.Base(BinaryName) defaultWorkspace := path.Join(usrCfg.Home, dirName) From ff73e58a2cb97be6a17c10b912da9aa44b5911f8 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Fri, 22 Jun 2018 16:51:23 -0600 Subject: [PATCH 3/3] Trim the suffix from the binary on Windows --- cmd/configure.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/configure.go b/cmd/configure.go index a9f392371..a9ac5c692 100644 --- a/cmd/configure.go +++ b/cmd/configure.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path" + "strings" "text/tabwriter" "github.com/exercism/cli/config" @@ -37,7 +38,7 @@ You can also override certain default settings to suit your preferences. } usrCfg.Normalize() if usrCfg.Workspace == "" { - dirName := path.Base(BinaryName) + dirName := strings.Replace(path.Base(BinaryName), ".exe", "", 1) defaultWorkspace := path.Join(usrCfg.Home, dirName) _, err := os.Stat(defaultWorkspace) // Sorry about the double negative.