Skip to content

Commit 201d358

Browse files
committed
feat: add total progress bar
1 parent 7c8121a commit 201d358

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/src/deploy.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ async fn handle_layer_progress_print(
142142
mut layers: tokio::sync::mpsc::Receiver<ostree_container::store::ImportProgress>,
143143
mut layer_bytes: tokio::sync::watch::Receiver<Option<ostree_container::store::LayerProgress>>,
144144
n_layers_to_fetch: usize,
145+
download_bytes: u64,
145146
) {
146147
let start = std::time::Instant::now();
147148
let mut total_read = 0u64;
@@ -150,23 +151,31 @@ async fn handle_layer_progress_print(
150151
n_layers_to_fetch.try_into().unwrap(),
151152
));
152153
let byte_bar = bar.add(indicatif::ProgressBar::new(0));
154+
let total_byte_bar = bar.add(indicatif::ProgressBar::new(download_bytes));
153155
// let byte_bar = indicatif::ProgressBar::new(0);
154156
// byte_bar.set_draw_target(indicatif::ProgressDrawTarget::hidden());
157+
println!("");
158+
layers_bar.inc(1);
155159
layers_bar.set_style(
156160
indicatif::ProgressStyle::default_bar()
157-
.template("{prefix} {bar} {pos}/{len} {wide_msg}")
161+
.template("{prefix} {pos}/{len} {bar:15}")
158162
.unwrap(),
159163
);
160-
layers_bar.set_prefix("Fetching layers");
164+
layers_bar.set_prefix("Fetching Layer");
161165
layers_bar.set_message("");
162-
byte_bar.set_prefix("Fetching");
163166
byte_bar.set_style(
164167
indicatif::ProgressStyle::default_bar()
165168
.template(
166-
" └ {prefix} {bar} {binary_bytes}/{binary_total_bytes} ({binary_bytes_per_sec}) {wide_msg}",
169+
" └ {bar:20} {msg} ({binary_bytes}/{binary_total_bytes})",
167170
)
168171
.unwrap()
169172
);
173+
total_byte_bar.set_prefix("Total");
174+
total_byte_bar.set_style(
175+
indicatif::ProgressStyle::default_bar()
176+
.template("\n{prefix} {bar:30} {binary_bytes}/{binary_total_bytes} ({binary_bytes_per_sec}, {elapsed}/{duration})")
177+
.unwrap(),
178+
);
170179
loop {
171180
tokio::select! {
172181
// Always handle layer changes first.
@@ -186,6 +195,7 @@ async fn handle_layer_progress_print(
186195
byte_bar.set_position(layer_size);
187196
layers_bar.inc(1);
188197
total_read = total_read.saturating_add(layer_size);
198+
total_byte_bar.set_position(total_read);
189199
}
190200
} else {
191201
// If the receiver is disconnected, then we're done
@@ -200,6 +210,7 @@ async fn handle_layer_progress_print(
200210
let bytes = layer_bytes.borrow();
201211
if let Some(bytes) = &*bytes {
202212
byte_bar.set_position(bytes.fetched);
213+
total_byte_bar.set_position(total_read + bytes.fetched);
203214
}
204215
}
205216
}
@@ -250,11 +261,13 @@ pub(crate) async fn pull(
250261
ostree_ext::cli::print_layer_status(&prep);
251262
let layers_to_fetch = prep.layers_to_fetch().collect::<Result<Vec<_>>>()?;
252263
let n_layers_to_fetch = layers_to_fetch.len();
264+
let download_bytes: u64 = layers_to_fetch.iter().map(|(l, _)| l.layer.size()).sum();
265+
253266
let printer = (!quiet).then(|| {
254267
let layer_progress = imp.request_progress();
255268
let layer_byte_progress = imp.request_layer_progress();
256269
tokio::task::spawn(async move {
257-
handle_layer_progress_print(layer_progress, layer_byte_progress, n_layers_to_fetch)
270+
handle_layer_progress_print(layer_progress, layer_byte_progress, n_layers_to_fetch, download_bytes)
258271
.await
259272
})
260273
});

ostree-ext/src/container/store.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub enum PrepareResult {
193193
#[derive(Debug)]
194194
pub struct ManifestLayerState {
195195
/// The underlying layer descriptor.
196-
pub(crate) layer: oci_image::Descriptor,
196+
pub layer: oci_image::Descriptor,
197197
// TODO semver: Make this readonly via an accessor
198198
/// The ostree ref name for this layer.
199199
pub ostree_ref: String,

0 commit comments

Comments
 (0)