From ce6701fb3381611f5c839e6ff76bd0a7b1bdfd80 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 24 Apr 2022 15:22:07 +0200 Subject: [PATCH] status: fix over-counted step when status != stepping This is a fixup of commit b00b61e9677209790ec9a018036e24b8ae336d52 Author: Christian Schwarz Date: Sun Nov 21 15:15:23 2021 +0100 status: user-visible replication step number should start at 1 fixes https://github.com/zrepl/zrepl/issues/589 refs https://github.com/zrepl/zrepl/issues/538 --- client/status/viewmodel/render.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/status/viewmodel/render.go b/client/status/viewmodel/render.go index 293efc8..aaaff77 100644 --- a/client/status/viewmodel/render.go +++ b/client/status/viewmodel/render.go @@ -228,8 +228,16 @@ func printFilesystemStatus(t *stringbuilder.B, rep *report.FilesystemReport, max } userVisisbleCurrentStep, userVisibleTotalSteps := rep.CurrentStep, len(rep.Steps) - if len(rep.Steps) > 0 { - userVisisbleCurrentStep = rep.CurrentStep + 1 // CurrentStep is an index that starts at 0 + // `.CurrentStep` is == len(rep.Steps) if all steps are done. + // Until then, it's an index into .Steps that starts at 0. + // For the user, we want it to start at 1. + if rep.CurrentStep >= len(rep.Steps) { + // rep.CurrentStep is what we want to show. + // We check for >= and not == for robustness. + } else { + // We're not done yet, so, make step count start at 1 + // (The `.State` is included in the output, indicating we're not done yet) + userVisisbleCurrentStep = rep.CurrentStep + 1 } status := fmt.Sprintf("%s (step %d/%d, %s/%s)%s", strings.ToUpper(string(rep.State)),