Skip to content

Commit ed04120

Browse files
committed
loopd: set network in default config path
1 parent d229a1a commit ed04120

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

loopd/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ var (
1818
defaultLogDirname = "logs"
1919
defaultLogFilename = "loopd.log"
2020
defaultLogDir = filepath.Join(loopDirBase, defaultLogDirname)
21-
defaultConfigFile = filepath.Join(loopDirBase, defaultConfigFilename)
21+
defaultConfigFile = filepath.Join(
22+
loopDirBase, defaultNetwork, defaultConfigFilename,
23+
)
2224

2325
defaultMaxLogFiles = 3
2426
defaultMaxLogFileSize = 10

loopd/run.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,7 @@ func Run(rpcCfg RPCConfig) error {
137137

138138
// Parse ini file.
139139
loopDir := lncfg.CleanAndExpandPath(config.LoopDir)
140-
configFile := lncfg.CleanAndExpandPath(config.ConfigFile)
141-
142-
// If our loop directory is set and the config file parameter is not
143-
// set, we assume that they want to point to a config file in their
144-
// loop dir. However, if the config file has a non-default value, then
145-
// we leave the config parameter as its custom value.
146-
if loopDir != loopDirBase && configFile == defaultConfigFile {
147-
configFile = filepath.Join(
148-
loopDir, defaultConfigFilename,
149-
)
150-
}
140+
configFile := getConfigPath(config, loopDir)
151141

152142
if err := flags.IniParse(configFile, &config); err != nil {
153143
// If it's a parsing related error, then we'll return
@@ -237,3 +227,25 @@ func Run(rpcCfg RPCConfig) error {
237227

238228
return fmt.Errorf("unimplemented command %v", parser.Active.Name)
239229
}
230+
231+
// getConfigPath gets our config path based on the values that are set in our
232+
// config.
233+
func getConfigPath(cfg Config, loopDir string) string {
234+
// If the config file path provided by the user is set, then we just
235+
// use this value.
236+
if cfg.ConfigFile != defaultConfigFile {
237+
return lncfg.CleanAndExpandPath(cfg.ConfigFile)
238+
}
239+
240+
// If the user has set a loop directory that is different to the default
241+
// we will use this loop directory as the location of our config file.
242+
// We do not namespace by network, because this is a custom loop dir.
243+
if loopDir != loopDirBase {
244+
return filepath.Join(loopDir, defaultConfigFilename)
245+
}
246+
247+
// Otherwise, we are using our default loop directory, and the user did
248+
// not set a config file path. We use our default loop dir, namespaced
249+
// by network.
250+
return filepath.Join(loopDir, cfg.Network, defaultConfigFilename)
251+
}

0 commit comments

Comments
 (0)