From 0fa1940dc0a7f9cab13094976e9139f2ce3b73e2 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Wed, 12 Mar 2025 08:37:41 +0000 Subject: [PATCH] cmd/geth: stop if import interrupted with multi files Signed-off-by: jsvisa --- cmd/geth/chaincmd.go | 3 +++ cmd/utils/cmd.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index eb0dda0952..f595df5e08 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -319,6 +319,9 @@ func importChain(ctx *cli.Context) error { if err := utils.ImportChain(chain, arg); err != nil { importErr = err log.Error("Import error", "file", arg, "err", err) + if err == utils.ErrImportInterrupted { + break + } } } } diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index de5918a722..33c93c2cc6 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -55,6 +55,9 @@ const ( importBatchSize = 2500 ) +// ErrImportInterrupted is returned when the user interrupts the import process. +var ErrImportInterrupted = errors.New("interrupted") + // Fatalf formats a message to standard error and exits the program. // The message is also printed to standard output if standard error // is redirected to a different file. @@ -191,7 +194,7 @@ func ImportChain(chain *core.BlockChain, fn string) error { for batch := 0; ; batch++ { // Load a batch of RLP blocks. if checkInterrupt() { - return errors.New("interrupted") + return ErrImportInterrupted } i := 0 for ; i < importBatchSize; i++ {