Merge pull request #4622 from guggero/config-mkdir
config: create all directories
This commit is contained in:
commit
98da919bf1
49
config.go
49
config.go
@ -552,23 +552,28 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the lnd directory if it doesn't already exist.
|
|
||||||
funcName := "loadConfig"
|
funcName := "loadConfig"
|
||||||
if err := os.MkdirAll(lndDir, 0700); err != nil {
|
makeDirectory := func(dir string) error {
|
||||||
// Show a nicer error message if it's because a symlink is
|
err := os.MkdirAll(dir, 0700)
|
||||||
// linked to a directory that does not exist (probably because
|
if err != nil {
|
||||||
// it's not mounted).
|
// Show a nicer error message if it's because a symlink
|
||||||
if e, ok := err.(*os.PathError); ok && os.IsExist(err) {
|
// is linked to a directory that does not exist
|
||||||
if link, lerr := os.Readlink(e.Path); lerr == nil {
|
// (probably because it's not mounted).
|
||||||
str := "is symlink %s -> %s mounted?"
|
if e, ok := err.(*os.PathError); ok && os.IsExist(err) {
|
||||||
err = fmt.Errorf(str, e.Path, link)
|
link, lerr := os.Readlink(e.Path)
|
||||||
|
if lerr == nil {
|
||||||
|
str := "is symlink %s -> %s mounted?"
|
||||||
|
err = fmt.Errorf(str, e.Path, link)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str := "%s: Failed to create lnd directory: %v"
|
||||||
|
err := fmt.Errorf(str, funcName, err)
|
||||||
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
str := "%s: Failed to create lnd directory: %v"
|
return nil
|
||||||
err := fmt.Errorf(str, funcName, err)
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// As soon as we're done parsing configuration options, ensure all paths
|
// As soon as we're done parsing configuration options, ensure all paths
|
||||||
@ -590,6 +595,24 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
|||||||
cfg.Tor.WatchtowerKeyPath = CleanAndExpandPath(cfg.Tor.WatchtowerKeyPath)
|
cfg.Tor.WatchtowerKeyPath = CleanAndExpandPath(cfg.Tor.WatchtowerKeyPath)
|
||||||
cfg.Watchtower.TowerDir = CleanAndExpandPath(cfg.Watchtower.TowerDir)
|
cfg.Watchtower.TowerDir = CleanAndExpandPath(cfg.Watchtower.TowerDir)
|
||||||
|
|
||||||
|
// Create the lnd directory and all other sub directories if they don't
|
||||||
|
// already exist. This makes sure that directory trees are also created
|
||||||
|
// for files that point to outside of the lnddir.
|
||||||
|
dirs := []string{
|
||||||
|
lndDir, cfg.DataDir,
|
||||||
|
cfg.LetsEncryptDir, cfg.Watchtower.TowerDir,
|
||||||
|
filepath.Dir(cfg.TLSCertPath), filepath.Dir(cfg.TLSKeyPath),
|
||||||
|
filepath.Dir(cfg.AdminMacPath), filepath.Dir(cfg.ReadMacPath),
|
||||||
|
filepath.Dir(cfg.InvoiceMacPath),
|
||||||
|
filepath.Dir(cfg.Tor.PrivateKeyPath),
|
||||||
|
filepath.Dir(cfg.Tor.WatchtowerKeyPath),
|
||||||
|
}
|
||||||
|
for _, dir := range dirs {
|
||||||
|
if err := makeDirectory(dir); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that the user didn't attempt to specify negative values for
|
// Ensure that the user didn't attempt to specify negative values for
|
||||||
// any of the autopilot params.
|
// any of the autopilot params.
|
||||||
if cfg.Autopilot.MaxChannels < 0 {
|
if cfg.Autopilot.MaxChannels < 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user