Skip to content

Commit

Permalink
Use platform independent pathnames
Browse files Browse the repository at this point in the history
  • Loading branch information
kytrinyx committed Sep 13, 2014
1 parent aea9522 commit 17fc164
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *Config) Read(file string) error {
if err != nil {
return err
}
file = fmt.Sprintf("%s/%s", home, File)
file = filepath.Join(home, File)
}

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

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

// fall back to default value
if c.Dir == "" {
c.Dir = fmt.Sprintf("%s/%s", dir, DirExercises)
c.Dir = filepath.Join(dir, DirExercises)
}
c.Dir = strings.Replace(c.Dir, "~/", fmt.Sprintf("%s/", dir), 1)
return c, nil
Expand All @@ -201,7 +201,7 @@ func FilePath(file string) (string, error) {
if err != nil {
return "", err
}
return fmt.Sprintf("%s/%s", dir, File), nil
return filepath.Join(dir, File), nil
}

// IsAuthenticated returns true if the config contains an API key.
Expand Down
5 changes: 2 additions & 3 deletions handlers/item.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handlers

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -17,7 +16,7 @@ type Item struct {
}

func (it *Item) Path() string {
return fmt.Sprintf("%s/%s", it.dir, it.Problem.ID)
return filepath.Join(it.dir, it.TrackID, it.Slug)
}

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

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

err := os.MkdirAll(filepath.Dir(file), 0755)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions handlers/logout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package handlers

import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"

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

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

c := config.Config{}
c.SavePath(file)
Expand Down

0 comments on commit 17fc164

Please sign in to comment.