Skip to content

admin/upload_index: Use indicatif for progress reporting #4836

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

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ hex = "=0.4.3"
http = "=0.2.7"
hyper = { version = "=0.14.19", features = ["client", "http1"] }
indexmap = { version = "=1.8.2", features = ["serde-1"] }
indicatif = "=0.16.2"
ipnetwork = "=0.19.0"
tikv-jemallocator = { version = "=0.5.0", features = ['unprefixed_malloc_on_supported_platforms', 'profiling'] }
lettre = { version = "=0.10.0-rc.6", default-features = false, features = ["file-transport", "smtp-transport", "native-tls", "hostname", "builder"] }
Expand Down
18 changes: 6 additions & 12 deletions src/admin/upload_index.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::time::{Duration, Instant};

use crate::admin::dialoguer;
use cargo_registry_index::{Repository, RepositoryConfig};
use indicatif::{ProgressBar, ProgressIterator, ProgressStyle};
use reqwest::blocking::Client;

use crate::config;
Expand Down Expand Up @@ -33,23 +32,18 @@ pub fn run(opts: Opts) -> anyhow::Result<()> {
return Ok(());
}

let mut progress_update_time = Instant::now();
for (i, file) in files.iter().enumerate() {
let pb = ProgressBar::new(files.len() as u64);
pb.set_style(ProgressStyle::default_bar().template("{bar:60} ({pos}/{len}, ETA {eta})"));

for file in files.iter().progress_with(pb) {
let crate_name = file.file_name().unwrap().to_str().unwrap();
let path = repo.index_file(crate_name);
if !path.exists() {
println!("skipping file `{}`", crate_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like when we call println!() while a progressbar is active it does not print the message, but instead freezes the progressbar and continues it on the next line. I guess it doesn't play well with the clearing of the current line.

continue;
}

let contents = std::fs::read_to_string(&path)?;
uploader.upload_index(&client, crate_name, contents)?;

// Print a progress update every 10 seconds.
let now = Instant::now();
if now - progress_update_time > Duration::from_secs(10) {
progress_update_time = now;
println!("uploading {}/{}", i, files.len());
}
}

println!(
Expand Down