1 // Copyright 2014 The go-ethereum Authors
2 // This file is part of the go-ethereum library.
4 // The go-ethereum library is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // The go-ethereum library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
28 // MakeName creates a node name that follows the ethereum convention
29 // for such names. It adds the operation system name and Go runtime version
31 func MakeName(name, version string) string {
32 return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version())
35 func ExpandHomePath(p string) (path string) {
37 sep := string(os.PathSeparator)
39 // Check in case of paths like "/something/~/something/"
40 if len(p) > 1 && p[:1+len(sep)] == "~"+sep {
41 usr, _ := user.Current()
44 path = strings.Replace(p, "~", dir, 1)
50 func FileExist(filePath string) bool {
51 _, err := os.Stat(filePath)
52 if err != nil && os.IsNotExist(err) {
59 func AbsolutePath(Datadir string, filename string) string {
60 if filepath.IsAbs(filename) {
63 return filepath.Join(Datadir, filename)
66 func HomeDir() string {
67 if home := os.Getenv("HOME"); home != "" {
70 if usr, err := user.Current(); err == nil {