File tree Expand file tree Collapse file tree 1 file changed +25
-8
lines changed
Expand file tree Collapse file tree 1 file changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -73,8 +73,13 @@ class ProgressBar : public Logger
7373 uint64_t corruptedPaths = 0 , untrustedPaths = 0 ;
7474
7575 bool active = true ;
76- bool paused = false ;
76+ size_t suspensions = 0 ;
7777 bool haveUpdate = true ;
78+
79+ bool isPaused () const
80+ {
81+ return suspensions > 0 ;
82+ }
7883 };
7984
8085 /* * Helps avoid unnecessary redraws, see `redraw()` */
@@ -130,18 +135,30 @@ class ProgressBar : public Logger
130135
131136 void pause () override {
132137 auto state (state_.lock ());
133- state->paused = true ;
138+ state->suspensions ++;
139+ if (state->suspensions > 1 ) {
140+ // already paused
141+ return ;
142+ }
143+
134144 if (state->active )
135145 writeToStderr (" \r \e[K" );
136146 }
137147
138148 void resume () override {
139149 auto state (state_.lock ());
140- state->paused = false ;
141- if (state->active )
142- writeToStderr (" \r \e[K" );
143- state->haveUpdate = true ;
144- updateCV.notify_one ();
150+ if (state->suspensions == 0 ) {
151+ log (lvlError, " nix::ProgressBar: resume() called without a matching preceding pause(). This is a bug." );
152+ return ;
153+ } else {
154+ state->suspensions --;
155+ }
156+ if (state->suspensions == 0 ) {
157+ if (state->active )
158+ writeToStderr (" \r \e[K" );
159+ state->haveUpdate = true ;
160+ updateCV.notify_one ();
161+ }
145162 }
146163
147164 bool isVerbose () override
@@ -383,7 +400,7 @@ class ProgressBar : public Logger
383400 auto nextWakeup = std::chrono::milliseconds::max ();
384401
385402 state.haveUpdate = false ;
386- if (state.paused || !state.active ) return nextWakeup;
403+ if (state.isPaused () || !state.active ) return nextWakeup;
387404
388405 std::string line;
389406
You can’t perform that action at this time.
0 commit comments