Skip to content

Conversation

cgwalters
Copy link
Collaborator

  • Indicatif instead of eprintln! ensures we handle ttys vs not always; on a non-tty we're silent
  • Use a proper async task instead of a try+sleep loop
  • But do try once outside of the await to make the happy path avoid emitting a wait message

- Indicatif instead of eprintln! ensures we handle ttys vs not always;
  on a non-tty we're silent
- Use a proper async task instead of a try+sleep loop
- But do try once outside of the await to make the happy path
  avoid emitting a wait message

Signed-off-by: Colin Walters <walters@verbum.org>
@bootc-bot bootc-bot bot requested a review from ckyrouac August 20, 2025 16:07
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a nice improvement by using indicatif for a better user experience when waiting for a sysroot lock, replacing a manual print and sleep loop. The new async_task_with_spinner utility is a good abstraction. My review includes a suggestion to refactor the lock acquisition logic to reduce code duplication and another to improve the panic safety of the new spinner utility.

Comment on lines +40 to +50
if sysroot.try_lock()? {
return Ok(Self {
sysroot: sysroot.clone(),
unowned: false,
});
}
async_task_with_spinner("Waiting for sysroot lock...", sysroot.lock_future()).await?;
Ok(Self {
sysroot: sysroot.clone(),
unowned: false,
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to construct the SysrootLock is duplicated. You can refactor this to avoid repetition by handling the case where the lock isn't immediately available, and then having a single point of SysrootLock creation. This will make the code more maintainable.

Suggested change
if sysroot.try_lock()? {
return Ok(Self {
sysroot: sysroot.clone(),
unowned: false,
});
}
async_task_with_spinner("Waiting for sysroot lock...", sysroot.lock_future()).await?;
Ok(Self {
sysroot: sysroot.clone(),
unowned: false,
})
if !sysroot.try_lock()? {
async_task_with_spinner("Waiting for sysroot lock...", sysroot.lock_future()).await?;
}
Ok(Self {
sysroot: sysroot.clone(),
unowned: false,
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but not worth blocking over

Comment on lines +11 to +18
let pb = indicatif::ProgressBar::new_spinner();
let style = indicatif::ProgressStyle::default_bar();
pb.set_style(style.template("{spinner} {msg}").unwrap());
pb.set_message(msg.to_string());
pb.enable_steady_tick(Duration::from_millis(150));
let r = f.await;
pb.finish_and_clear();
r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the future f panics, the await will unwind the stack and pb.finish_and_clear() will not be called, leaving the spinner on the screen. Using a RAII guard to manage the ProgressBar's lifetime ensures that it's cleaned up correctly even in the case of a panic.

Suggested change
let pb = indicatif::ProgressBar::new_spinner();
let style = indicatif::ProgressStyle::default_bar();
pb.set_style(style.template("{spinner} {msg}").unwrap());
pb.set_message(msg.to_string());
pb.enable_steady_tick(Duration::from_millis(150));
let r = f.await;
pb.finish_and_clear();
r
let pb = indicatif::ProgressBar::new_spinner();
let style = indicatif::ProgressStyle::default_bar();
pb.set_style(style.template("{spinner} {msg}").unwrap());
pb.set_message(msg.to_string());
pb.enable_steady_tick(Duration::from_millis(150));
struct Guard(indicatif::ProgressBar);
impl Drop for Guard {
fn drop(&mut self) {
self.0.finish_and_clear();
}
}
let _guard = Guard(pb);
f.await

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that's kinda wild that it noticed that. While I guess it's true... if we panic it's not like the fact that the spinner isn't cleared is the most jarring UX from the whole thing 😆

@jeckersb jeckersb merged commit 2cb3ef2 into bootc-dev:main Aug 20, 2025
28 checks passed
@cgwalters
Copy link
Collaborator Author

Fallout in #1547

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants