From 00335441cee3b8cca76c2b87dd9637aec2c773c0 Mon Sep 17 00:00:00 2001 From: Jie Hou Date: Tue, 19 Sep 2023 11:24:12 -0700 Subject: [PATCH] Auto remove existing chain if importing chain file or snapshot --- cmd/lotus/daemon.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 7271a6e53..dd61c9f8a 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -269,7 +269,17 @@ var DaemonCmd = &cli.Command{ } } - if cctx.Bool("remove-existing-chain") { + chainfile := cctx.String("import-chain") + snapshot := cctx.String("import-snapshot") + willImportChain := false + if chainfile != "" || snapshot != "" { + if chainfile != "" && snapshot != "" { + return fmt.Errorf("cannot specify both 'import-snapshot' and 'import-chain'") + } + willImportChain = true + } + + if cctx.Bool("remove-existing-chain") || willImportChain { lr, err := repo.NewFS(cctx.String("repo")) if err != nil { return xerrors.Errorf("error opening fs repo: %w", err) @@ -289,12 +299,7 @@ var DaemonCmd = &cli.Command{ } } - chainfile := cctx.String("import-chain") - snapshot := cctx.String("import-snapshot") - if chainfile != "" || snapshot != "" { - if chainfile != "" && snapshot != "" { - return fmt.Errorf("cannot specify both 'import-snapshot' and 'import-chain'") - } + if willImportChain { var issnapshot bool if chainfile == "" { chainfile = snapshot