Skip to content

Commit

Permalink
sysroot: Add total layer count to output
Browse files Browse the repository at this point in the history
It's useful to see in the progress output how many layers
there are to fetch.

This is similar to
containers/bootc@6eb5718
which ended up being totally reworked in a nicer way in
containers/bootc@d8b5df2

But doing the latter would require nontrivial changes to our
DBus API around status and progress reporting...and I'd
like to think about how we tackle that more generally
in e.g. containers/skopeo#658

Closes: #5024
  • Loading branch information
cgwalters committed Sep 3, 2024
1 parent 3c1bcef commit d631211
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions rust/src/sysroot_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ fn layer_counts<'a>(layers: impl Iterator<Item = &'a ManifestLayerState>) -> (u3
// Output when we begin/end fetching a layer. Ideally, we'd handle
// byte-level progress here too, but that requires some more sophisticated
// binding with the rpmostree-output.h via cxx.rs.
async fn layer_progress_print(mut r: Receiver<ImportProgress>) {
async fn layer_progress_print(mut r: Receiver<ImportProgress>, total_to_fetch: u32) {
// This is just used to hold a reference to the task.
#[allow(unused_variables, unused_assignments)]
let mut task = None;
let mut n_fetched = 0u64;
while let Some(v) = r.recv().await {
let msg = ostree_ext::cli::layer_progress_format(&v);
let mut msg = ostree_ext::cli::layer_progress_format(&v);
msg.insert_str(0, &format!("[{n_fetched}/{total_to_fetch}] "));
tracing::debug!("layer progress: {msg}");
match v {
ImportProgress::OstreeChunkStarted(_) => {
Expand All @@ -73,13 +75,15 @@ async fn layer_progress_print(mut r: Receiver<ImportProgress>) {
}
ImportProgress::OstreeChunkCompleted(_) => {
assert!(task.take().is_some());
n_fetched += 1;
}
ImportProgress::DerivedLayerStarted(_) => {
assert!(task.is_none());
task = Some(progress_begin_task(&msg));
}
ImportProgress::DerivedLayerCompleted(_) => {
assert!(task.take().is_some());
n_fetched += 1;
}
}
}
Expand Down Expand Up @@ -127,6 +131,7 @@ async fn pull_container_async(
.ostree_layers
.iter()
.chain(std::iter::once(&prep.ostree_commit_layer));
let mut total_to_fetch = 0;
let (stored, (n_to_fetch, size_to_fetch)) = layer_counts(ostree_layers);
if stored > 0 {
output_message(&format!("ostree chunk layers already present: {stored}"));
Expand All @@ -136,6 +141,7 @@ async fn pull_container_async(
output_message(&format!(
"ostree chunk layers needed: {n_to_fetch} ({size})"
));
total_to_fetch += n_to_fetch;
}
let (stored, (n_to_fetch, size_to_fetch)) = layer_counts(prep.layers.iter());
if stored > 0 {
Expand All @@ -144,12 +150,13 @@ async fn pull_container_async(
if n_to_fetch > 0 {
let size = glib::format_size(size_to_fetch);
output_message(&format!("custom layers needed: {n_to_fetch} ({size})"));
total_to_fetch += n_to_fetch;
}
let local = tokio::task::LocalSet::new();
let import = local
.run_until(async move {
let _progress_printer =
tokio::task::spawn_local(async move { layer_progress_print(layer_progress).await });
tokio::task::spawn_local(layer_progress_print(layer_progress, total_to_fetch));
imp.import(prep).await
})
.await;
Expand Down

0 comments on commit d631211

Please sign in to comment.