Skip to content

Commit 17fc164

Browse files
committed
Use platform independent pathnames
1 parent aea9522 commit 17fc164

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (c *Config) Read(file string) error {
9696
if err != nil {
9797
return err
9898
}
99-
file = fmt.Sprintf("%s/%s", home, File)
99+
file = filepath.Join(home, File)
100100
}
101101

102102
if _, err := os.Stat(file); err != nil {
@@ -176,7 +176,7 @@ func (c *Config) configure() (*Config, error) {
176176
if err != nil {
177177
return c, err
178178
}
179-
c.file = fmt.Sprintf("%s/%s", dir, File)
179+
c.file = filepath.Join(dir, File)
180180

181181
// use legacy value, if it exists
182182
if c.ExercismDirectory != "" {
@@ -185,7 +185,7 @@ func (c *Config) configure() (*Config, error) {
185185

186186
// fall back to default value
187187
if c.Dir == "" {
188-
c.Dir = fmt.Sprintf("%s/%s", dir, DirExercises)
188+
c.Dir = filepath.Join(dir, DirExercises)
189189
}
190190
c.Dir = strings.Replace(c.Dir, "~/", fmt.Sprintf("%s/", dir), 1)
191191
return c, nil
@@ -201,7 +201,7 @@ func FilePath(file string) (string, error) {
201201
if err != nil {
202202
return "", err
203203
}
204-
return fmt.Sprintf("%s/%s", dir, File), nil
204+
return filepath.Join(dir, File), nil
205205
}
206206

207207
// IsAuthenticated returns true if the config contains an API key.

handlers/item.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package handlers
22

33
import (
4-
"fmt"
54
"io/ioutil"
65
"os"
76
"path/filepath"
@@ -17,7 +16,7 @@ type Item struct {
1716
}
1817

1918
func (it *Item) Path() string {
20-
return fmt.Sprintf("%s/%s", it.dir, it.Problem.ID)
19+
return filepath.Join(it.dir, it.TrackID, it.Slug)
2120
}
2221

2322
func (it *Item) Matches(filter HWFilter) bool {
@@ -39,7 +38,7 @@ func (it *Item) Save() error {
3938
}
4039

4140
for name, text := range it.Files {
42-
file := fmt.Sprintf("%s/%s/%s", it.dir, it.ID, name)
41+
file := filepath.Join(it.Path(), name)
4342

4443
err := os.MkdirAll(filepath.Dir(file), 0755)
4544
if err != nil {

handlers/logout_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package handlers
22

33
import (
44
"flag"
5-
"fmt"
65
"io/ioutil"
76
"os"
7+
"path/filepath"
88
"testing"
99

1010
"github.com/codegangsta/cli"
@@ -16,7 +16,7 @@ func TestLogoutDeletesConfigFile(t *testing.T) {
1616
tmpDir, err := ioutil.TempDir("", "")
1717
assert.NoError(t, err)
1818

19-
file := fmt.Sprintf("%s/%s", tmpDir, config.File)
19+
file := filepath.Join(tmpDir, config.File)
2020

2121
c := config.Config{}
2222
c.SavePath(file)

0 commit comments

Comments
 (0)