use mitchellh/go-homedir instead of simple HOME lookup

This commit is contained in:
Henry 2014-10-15 12:21:16 +02:00
parent 0dd3316c16
commit c9236dd8e1

View File

@ -4,12 +4,12 @@ import (
"errors"
"io"
"math/rand"
"os"
"path/filepath"
"strings"
"time"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
)
func init() {
@ -35,7 +35,11 @@ var ErrNotFound = ds.ErrNotFound
// TildeExpansion expands a filename, which may begin with a tilde.
func TildeExpansion(filename string) (string, error) {
if strings.HasPrefix(filename, "~/") {
filename = strings.Replace(filename, "~", os.Getenv("HOME"), 1)
var err error
filename, err = homedir.Expand(filename)
if err != nil {
return "", err
}
}
return filename, nil
}