Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysroot: Add total layer count to output #5061

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading