提交 c9236dd8 作者: Henry

use mitchellh/go-homedir instead of simple HOME lookup

上级 0dd3316c
...@@ -4,12 +4,12 @@ import ( ...@@ -4,12 +4,12 @@ import (
"errors" "errors"
"io" "io"
"math/rand" "math/rand"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go" 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() { func init() {
...@@ -35,7 +35,11 @@ var ErrNotFound = ds.ErrNotFound ...@@ -35,7 +35,11 @@ var ErrNotFound = ds.ErrNotFound
// TildeExpansion expands a filename, which may begin with a tilde. // TildeExpansion expands a filename, which may begin with a tilde.
func TildeExpansion(filename string) (string, error) { func TildeExpansion(filename string) (string, error) {
if strings.HasPrefix(filename, "~/") { 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 return filename, nil
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论