Skip to content

Commit dd57e8f

Browse files
committed
cmd/loop: fix path options and loopDir interaction
According to the comment in the code, loopdir should affect tls cert path and macaroon path only if custom values were not set for them. However the actual code ignored custom tls cert path and macaroon path if loopdir and/or network was changed. For instance, the following call: loop --network regtest --tlscertpath tls.cert --macaroonpath loop.macaroon resulted in using ~/.loop/regtest/tls.cert and ~/.loop/regtest/loop.macaroon instead of the files provided. This commit fixes the code to match the description in the comment. Also the comment was updated to mention custom network setting in addition to custom loopdir.
1 parent d8361e3 commit dd57e8f

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

cmd/loop/main.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,25 +193,33 @@ func extractPathArgs(ctx *cli.Context) (string, string, error) {
193193
// properly read the macaroons and also the cert. This will either be
194194
// the default, or will have been overwritten by the end user.
195195
loopDir := lncfg.CleanAndExpandPath(ctx.GlobalString(loopDirFlag.Name))
196-
tlsCertPath := lncfg.CleanAndExpandPath(ctx.GlobalString(
197-
tlsCertFlag.Name,
198-
))
199-
macPath := lncfg.CleanAndExpandPath(ctx.GlobalString(
200-
macaroonPathFlag.Name,
201-
))
202196

203-
// If a custom loop directory was set, we'll also check if custom paths
204-
// for the TLS cert and macaroon file were set as well. If not, we'll
205-
// override their paths so they can be found within the custom loop
206-
// directory set. This allows us to set a custom loop directory, along
207-
// with custom paths to the TLS cert and macaroon file.
197+
tlsCertPathRaw := ctx.GlobalString(tlsCertFlag.Name)
198+
tlsCertPath := lncfg.CleanAndExpandPath(tlsCertPathRaw)
199+
200+
macPathRaw := ctx.GlobalString(macaroonPathFlag.Name)
201+
macPath := lncfg.CleanAndExpandPath(macPathRaw)
202+
203+
// If a custom loop directory or network was set, we'll also check if
204+
// custom paths for the TLS cert and macaroon file were set as well. If
205+
// not, we'll override their paths so they can be found within the
206+
// custom loop directory set. This allows us to set a custom loop
207+
// directory and/or network, along with custom paths to the TLS cert and
208+
// macaroon file.
208209
if loopDir != loopd.LoopDirBase || networkStr != loopd.DefaultNetwork {
209-
tlsCertPath = filepath.Join(
210-
loopDir, networkStr, loopd.DefaultTLSCertFilename,
211-
)
212-
macPath = filepath.Join(
213-
loopDir, networkStr, loopd.DefaultMacaroonFilename,
214-
)
210+
if tlsCertPathRaw == loopd.DefaultTLSCertPath {
211+
tlsCertPath = filepath.Join(
212+
loopDir, networkStr,
213+
loopd.DefaultTLSCertFilename,
214+
)
215+
}
216+
217+
if macPathRaw == loopd.DefaultMacaroonPath {
218+
macPath = filepath.Join(
219+
loopDir, networkStr,
220+
loopd.DefaultMacaroonFilename,
221+
)
222+
}
215223
}
216224

217225
return tlsCertPath, macPath, nil

0 commit comments

Comments
 (0)