Skip to content

Commit cc00d48

Browse files
RoyLinRoyLin
authored andcommitted
feat(pull): improve layer download progress display
Enhanced the pull progress display to show download status for each layer: - Shows "Downloading X MB..." when starting to download a layer - Shows "X MB ✓" when layer download completes - Uses \r to overwrite the same line for cleaner output - Properly formats sizes (MB/KB/B) based on layer size Changes: - Modified progress callback to be called twice per layer (start + complete) - Use negative size value to signal completion in the callback - Updated both `pull` and `run` commands to use the new progress format This provides better visibility into the download process, especially for large images with multiple layers.
1 parent f3c28a4 commit cc00d48

5 files changed

Lines changed: 60 additions & 23 deletions

File tree

src/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
resolver = "2"
1313

1414
[workspace.package]
15-
version = "0.8.3"
15+
version = "0.8.4"
1616
edition = "2021"
1717
authors = ["A3S Lab Team"]
1818
license = "MIT"

src/cli/src/commands/pull.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,30 @@ pub async fn execute(args: PullArgs) -> Result<(), Box<dyn std::error::Error>> {
6161
println!("Pulling {}...", args.image);
6262
puller = puller.with_progress_fn(std::sync::Arc::new(|current, total, digest, size| {
6363
let short = &digest[digest.len().saturating_sub(12)..];
64-
let size_str = if size >= 1_048_576 {
65-
format!("{:.1} MB", size as f64 / 1_048_576.0)
66-
} else if size >= 1024 {
67-
format!("{:.1} KB", size as f64 / 1024.0)
64+
if size < 0 {
65+
// Negative size signals completion
66+
let actual_size = (-size) as i64;
67+
let size_str = if actual_size >= 1_048_576 {
68+
format!("{:.1} MB", actual_size as f64 / 1_048_576.0)
69+
} else if actual_size >= 1024 {
70+
format!("{:.1} KB", actual_size as f64 / 1024.0)
71+
} else {
72+
format!("{} B", actual_size)
73+
};
74+
eprintln!("\r [{current}/{total}] {short}: {size_str} ✓");
6875
} else {
69-
format!("{} B", size)
70-
};
71-
println!(" [{current}/{total}] {short}: {size_str}");
76+
// Positive size means downloading
77+
let size_str = if size >= 1_048_576 {
78+
format!("{:.1} MB", size as f64 / 1_048_576.0)
79+
} else if size >= 1024 {
80+
format!("{:.1} KB", size as f64 / 1024.0)
81+
} else {
82+
format!("{} B", size)
83+
};
84+
eprint!("\r [{current}/{total}] {short}: Downloading {size_str}...");
85+
use std::io::Write;
86+
let _ = std::io::stderr().flush();
87+
}
7288
}));
7389
}
7490
let image = puller.pull(&args.image).await?;

src/cli/src/commands/run.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,34 @@ async fn setup_and_boot(args: &RunArgs) -> Result<RunContext, Box<dyn std::error
191191

192192
let image_name = args.common.image.clone();
193193
vm.set_pull_progress_fn(std::sync::Arc::new(move |current, total, digest, size| {
194-
if current == 1 {
194+
if current == 1 && size > 0 {
195195
println!("Pulling {}...", image_name);
196196
}
197197
let short = &digest[digest.len().saturating_sub(12)..];
198-
let size_str = if size >= 1_048_576 {
199-
format!("{:.1} MB", size as f64 / 1_048_576.0)
200-
} else if size >= 1024 {
201-
format!("{:.1} KB", size as f64 / 1024.0)
198+
if size < 0 {
199+
// Negative size signals completion
200+
let actual_size = (-size) as i64;
201+
let size_str = if actual_size >= 1_048_576 {
202+
format!("{:.1} MB", actual_size as f64 / 1_048_576.0)
203+
} else if actual_size >= 1024 {
204+
format!("{:.1} KB", actual_size as f64 / 1024.0)
205+
} else {
206+
format!("{} B", actual_size)
207+
};
208+
eprintln!("\r [{current}/{total}] {short}: {size_str} ✓");
202209
} else {
203-
format!("{} B", size)
204-
};
205-
println!(" [{current}/{total}] {short}: {size_str}");
210+
// Positive size means downloading
211+
let size_str = if size >= 1_048_576 {
212+
format!("{:.1} MB", size as f64 / 1_048_576.0)
213+
} else if size >= 1024 {
214+
format!("{:.1} KB", size as f64 / 1024.0)
215+
} else {
216+
format!("{} B", size)
217+
};
218+
eprint!("\r [{current}/{total}] {short}: Downloading {size_str}...");
219+
use std::io::Write;
220+
let _ = std::io::stderr().flush();
221+
}
206222
}));
207223

208224
connect_network(args.common.network.as_deref(), &box_id, &name)?;

src/runtime/src/oci/registry.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ impl RegistryPuller {
315315
message: format!("Failed to pull layer {}: {}", layer.digest, e),
316316
})?;
317317

318+
// Call progress callback again with negative size to signal completion
319+
if let Some(ref f) = self.progress_fn {
320+
f(idx + 1, total, &layer.digest, -(layer.size as i64));
321+
}
322+
318323
let layer_digest_hex = layer
319324
.digest
320325
.strip_prefix("sha256:")

0 commit comments

Comments
 (0)