config: move directory creation to after path fixes

Fixes #5927.
This commit moves the code that attempts to create parent directories to
the correct place _after_ we've adjusted all path values to point to the
correct places. Before this commit the macaroon and tor paths would
point to their default locations, even if the --lnddir flag was
specified.
This commit is contained in:
Oliver Gugger 2021-11-08 15:28:54 +01:00
parent 35b4382f7a
commit 842221aab2
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

View File

@ -740,8 +740,8 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
} }
} }
str := "Failed to create lnd directory: %v" str := "Failed to create lnd directory '%s': %v"
return mkErr(str, err) return mkErr(str, dir, err)
} }
return nil return nil
@ -809,24 +809,6 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
cfg.WalletUnlockPasswordFile, cfg.WalletUnlockPasswordFile,
) )
// 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 {
@ -1307,12 +1289,6 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name), lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
) )
// We need to make sure the default network directory exists for when we
// try to create our default macaroons there.
if err := makeDirectory(cfg.networkDir); err != nil {
return nil, err
}
// If a custom macaroon directory wasn't specified and the data // If a custom macaroon directory wasn't specified and the data
// directory has changed from the default path, then we'll also update // directory has changed from the default path, then we'll also update
// the path for the macaroons to be generated. // the path for the macaroons to be generated.
@ -1332,6 +1308,24 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
) )
} }
// 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 the lnddir.
dirs := []string{
lndDir, cfg.DataDir, cfg.networkDir,
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
}
}
// Similarly, if a custom back up file path wasn't specified, then // Similarly, if a custom back up file path wasn't specified, then
// we'll update the file location to match our set network directory. // we'll update the file location to match our set network directory.
if cfg.BackupFilePath == "" { if cfg.BackupFilePath == "" {