mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
26 lines
541 B
Go
26 lines
541 B
Go
|
package internal
|
||
|
|
||
|
import (
|
||
|
"os/user"
|
||
|
"path/filepath"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
// ExpandPath will check if the given path begins with a "~" symbol, and if so,
|
||
|
// will expand it to become the user's home directory. If it fails to expand the
|
||
|
// path it will automatically return the original path itself.
|
||
|
func ExpandPath(path string) string {
|
||
|
usr, err := user.Current()
|
||
|
if err != nil {
|
||
|
return path
|
||
|
}
|
||
|
|
||
|
if path == "~" {
|
||
|
return usr.HomeDir
|
||
|
} else if strings.HasPrefix(path, "~/") {
|
||
|
return filepath.Join(usr.HomeDir, path[2:])
|
||
|
}
|
||
|
|
||
|
return path
|
||
|
}
|