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:
parent
36e06cdd35
commit
862729809e
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -236,7 +237,15 @@ func main() {
|
|||||||
func cleanAndExpandPath(path string) string {
|
func cleanAndExpandPath(path string) string {
|
||||||
// Expand initial ~ to OS specific home directory.
|
// Expand initial ~ to OS specific home directory.
|
||||||
if strings.HasPrefix(path, "~") {
|
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)
|
path = strings.Replace(path, "~", homeDir, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
config.go
11
config.go
@ -9,6 +9,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -609,7 +610,15 @@ func loadConfig() (*config, error) {
|
|||||||
func cleanAndExpandPath(path string) string {
|
func cleanAndExpandPath(path string) string {
|
||||||
// Expand initial ~ to OS specific home directory.
|
// Expand initial ~ to OS specific home directory.
|
||||||
if strings.HasPrefix(path, "~") {
|
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)
|
path = strings.Replace(path, "~", homeDir, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user