config+cmd/lncli: make cleanAndExpandPath return empty string on empty path

Co-Authored-By: Karl Ranna <karl@karlranna.com>
This commit is contained in:
Wilmer Paulino 2018-08-22 15:25:55 -04:00 committed by Olaoluwa Osuntokun
parent 646e81262f
commit 6ddae25487
2 changed files with 8 additions and 2 deletions

@ -252,10 +252,13 @@ func main() {
// passed path, cleans the result, and returns it. // passed path, cleans the result, and returns it.
// This function is taken from https://github.com/btcsuite/btcd // This function is taken from https://github.com/btcsuite/btcd
func cleanAndExpandPath(path string) string { func cleanAndExpandPath(path string) string {
if path == "" {
return ""
}
// Expand initial ~ to OS specific home directory. // Expand initial ~ to OS specific home directory.
if strings.HasPrefix(path, "~") { if strings.HasPrefix(path, "~") {
var homeDir string var homeDir string
user, err := user.Current() user, err := user.Current()
if err == nil { if err == nil {
homeDir = user.HomeDir homeDir = user.HomeDir

@ -934,10 +934,13 @@ func loadConfig() (*config, error) {
// passed path, cleans the result, and returns it. // passed path, cleans the result, and returns it.
// This function is taken from https://github.com/btcsuite/btcd // This function is taken from https://github.com/btcsuite/btcd
func cleanAndExpandPath(path string) string { func cleanAndExpandPath(path string) string {
if path == "" {
return ""
}
// Expand initial ~ to OS specific home directory. // Expand initial ~ to OS specific home directory.
if strings.HasPrefix(path, "~") { if strings.HasPrefix(path, "~") {
var homeDir string var homeDir string
user, err := user.Current() user, err := user.Current()
if err == nil { if err == nil {
homeDir = user.HomeDir homeDir = user.HomeDir