execenv: fix some cache building progress bar artifact

Michael Muré created

Still one issue remaining: the last bar doesn't dissapear. Looks like a mbp issue.

Change summary

cache/repo_cache.go         | 5 +++++
commands/execenv/loading.go | 8 ++++++--
2 files changed, 11 insertions(+), 2 deletions(-)

Detailed changes

cache/repo_cache.go 🔗

@@ -210,10 +210,15 @@ type BuildEventType int
 
 const (
 	_ BuildEventType = iota
+	// BuildEventCacheIsBuilt signal that the cache is being built (aka, not skipped)
 	BuildEventCacheIsBuilt
+	// BuildEventRemoveLock signal that an old repo lock has been cleaned
 	BuildEventRemoveLock
+	// BuildEventStarted signal the beginning of a cache build for an entity
 	BuildEventStarted
+	// BuildEventProgress signal progress in the cache building for an entity
 	BuildEventProgress
+	// BuildEventFinished signal the end of a cache build for an entity
 	BuildEventFinished
 )
 

commands/execenv/loading.go 🔗

@@ -156,13 +156,17 @@ func CacheBuildProgressBar(env *Env, events chan cache.BuildEvent) error {
 				mpb.AppendDecorators(decor.Percentage(decor.WCSyncSpace)),
 			)
 		case cache.BuildEventProgress:
-			bars[event.Typename].SetTotal(event.Total, false)
 			bars[event.Typename].SetCurrent(event.Progress)
+			bars[event.Typename].SetTotal(event.Total, event.Progress == event.Total)
+		case cache.BuildEventFinished:
+			if bar := bars[event.Typename]; !bar.Completed() {
+				bar.SetTotal(0, true)
+			}
 		}
 	}
 
 	if progress != nil {
-		progress.Shutdown()
+		progress.Wait()
 	}
 
 	return nil