@cryptotaxi247 / kubo / commits / c9236dd8e

use mitchellh/go-homedir instead of simple HOME lookup

Henry committed Oct 15, 2014 at 12:21 UTC c9236dd8e1e1859072fdec3b552ebddd5b9661c0
1 file changed +6 -2
util/util.go
+6 -2
@@ -4,12 +4,12 @@ import (
4 "errors"
5 "io"
6 "math/rand"
7 - "os"
7 "path/filepath"
8 "strings"
9 "time"
10
11 ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
12 + "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
13 )
14
15 func init() {
@@ -35,7 +35,11 @@ var ErrNotFound = ds.ErrNotFound
35 // TildeExpansion expands a filename, which may begin with a tilde.
36 func TildeExpansion(filename string) (string, error) {
37 if strings.HasPrefix(filename, "~/") {
38 - filename = strings.Replace(filename, "~", os.Getenv("HOME"), 1)
38 + var err error
39 + filename, err = homedir.Expand(filename)
40 + if err != nil {
41 + return "", err
42 + }
43 }
44 return filename, nil
45 }