config+cmd/lncli: ensure tilde in path is expanded to home dir

Since we're now able to create a base LND directory that no longer lives
under the OS specific application data directory, we modify
cleanAndExpandPath to replace the `~` in a path to the current user's
home directory, rather than the user's application data directory.
This commit is contained in:
Wilmer Paulino committed 2018-03-12 22:24:04 -04:00
1 parent 36e06cdd35
commit 862729809e
2 files changed
+20 -2

No files matched your search

+10 -1
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
@@ -236,7 +237,15 @@ func main() {
func cleanAndExpandPath(path string) string {
// Expand initial ~ to OS specific home directory.
if strings.HasPrefix(path, "~") {
homeDir := filepath.Dir(defaultLndDir)
var homeDir string
user, err := user.Current()
if err == nil {
homeDir = user.HomeDir
} else {
homeDir = os.Getenv("HOME")
}
path = strings.Replace(path, "~", homeDir, 1)
}
+10 -1
View File
@@ -9,6 +9,7 @@ import (
"io/ioutil"
"net"
"os"
"os/user"
"path"
"path/filepath"
"regexp"
@@ -609,7 +610,15 @@ func loadConfig() (*config, error) {
func cleanAndExpandPath(path string) string {
// Expand initial ~ to OS specific home directory.
if strings.HasPrefix(path, "~") {
homeDir := filepath.Dir(defaultLndDir)
var homeDir string
user, err := user.Current()
if err == nil {
homeDir = user.HomeDir
} else {
homeDir = os.Getenv("HOME")
}
path = strings.Replace(path, "~", homeDir, 1)
}