common, node: move datadir defaults into package node

This commit is contained in:
Felix Lange
2016-09-16 11:53:50 +02:00
parent eeb322ae64
commit b42a5b118f
7 changed files with 43 additions and 49 deletions

View File

@ -19,10 +19,8 @@ package common
import (
"fmt"
"os"
"os/user"
"path/filepath"
"runtime"
"strings"
)
// MakeName creates a node name that follows the ethereum convention
@ -32,21 +30,6 @@ func MakeName(name, version string) string {
return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version())
}
func ExpandHomePath(p string) (path string) {
path = p
sep := string(os.PathSeparator)
// Check in case of paths like "/something/~/something/"
if len(p) > 1 && p[:1+len(sep)] == "~"+sep {
usr, _ := user.Current()
dir := usr.HomeDir
path = strings.Replace(p, "~", dir, 1)
}
return
}
func FileExist(filePath string) bool {
_, err := os.Stat(filePath)
if err != nil && os.IsNotExist(err) {
@ -62,13 +45,3 @@ func AbsolutePath(Datadir string, filename string) string {
}
return filepath.Join(Datadir, filename)
}
func HomeDir() string {
if home := os.Getenv("HOME"); home != "" {
return home
}
if usr, err := user.Current(); err == nil {
return usr.HomeDir
}
return ""
}