Skip to content

Commit 175941e

Browse files
authored
Merge pull request #272 from carlaKC/config-fixdefaultconfigpath
loopd: add network to default config file path
2 parents 048a365 + ed04120 commit 175941e

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

loopd/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import (
1313
var (
1414
loopDirBase = btcutil.AppDataDir("loop", false)
1515

16+
defaultNetwork = "mainnet"
1617
defaultLogLevel = "info"
1718
defaultLogDirname = "logs"
1819
defaultLogFilename = "loopd.log"
1920
defaultLogDir = filepath.Join(loopDirBase, defaultLogDirname)
20-
defaultConfigFile = filepath.Join(loopDirBase, defaultConfigFilename)
21+
defaultConfigFile = filepath.Join(
22+
loopDirBase, defaultNetwork, defaultConfigFilename,
23+
)
2124

2225
defaultMaxLogFiles = 3
2326
defaultMaxLogFileSize = 10
@@ -75,7 +78,7 @@ const (
7578
// DefaultConfig returns all default values for the Config struct.
7679
func DefaultConfig() Config {
7780
return Config{
78-
Network: "mainnet",
81+
Network: defaultNetwork,
7982
RPCListen: "localhost:11010",
8083
RESTListen: "localhost:8081",
8184
Server: &loopServerConfig{

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)