use super::install::{Installation, UpdateLock};
use anyhow::{Context, Result};
use std::time::Duration;
pub(super) async fn acquire(
installation: &Installation,
automatic: bool,
) -> Result<Option<UpdateLock>> {
if let Some(lock) = installation.try_lock()? {
return Ok(Some(lock));
}
if automatic {
return Ok(None);
}
let _progress = crate::ui::Progress::start("Waiting for running update; Ctrl-C stops waiting");
tokio::time::timeout(Duration::from_secs(35 * 60), async {
loop {
tokio::time::sleep(Duration::from_millis(250)).await;
if let Some(lock) = installation.try_lock()? {
return Ok(Some(lock));
}
}
})
.await
.context(
"update is still busy after 35 minutes; run gent update status and inspect its build log",
)?
}