Skip to content
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
72 changes: 37 additions & 35 deletions src/bin/crates-admin/upload_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crates_io::tasks::spawn_blocking;
use crates_io_index::{Repository, RepositoryConfig};
use indicatif::{ProgressBar, ProgressIterator, ProgressStyle};
use tokio::runtime::Handle;

#[derive(clap::Parser, Debug)]
#[command(
Expand All @@ -17,52 +16,55 @@
}

pub async fn run(opts: Opts) -> anyhow::Result<()> {
spawn_blocking(move || {
let storage = Storage::from_environment();
let storage = Storage::from_environment();

Check warning on line 19 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L19

Added line #L19 was not covered by tests

println!("fetching git repo");
let config = RepositoryConfig::from_environment()?;
println!("fetching git repo");
let config = RepositoryConfig::from_environment()?;
let (repo, files) = spawn_blocking(move || {

Check warning on line 23 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L21-L23

Added lines #L21 - L23 were not covered by tests
let repo = Repository::open(&config)?;
repo.reset_head()?;
println!("HEAD is at {}", repo.head_oid()?);

let files = repo.get_files_modified_since(opts.incremental_commit.as_deref())?;
println!("found {} files to upload", files.len());
if !dialoguer::confirm("continue with upload?")? {
return Ok(());
}

let pb = ProgressBar::new(files.len() as u64);
pb.set_style(ProgressStyle::with_template(
"{bar:60} ({pos}/{len}, ETA {eta})",
)?);
Ok::<_, anyhow::Error>((repo, files))
})
.await?;

Check warning on line 33 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L31-L33

Added lines #L31 - L33 were not covered by tests

if !dialoguer::async_confirm("continue with upload?").await? {
return Ok(());
}

Check warning on line 37 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L35-L37

Added lines #L35 - L37 were not covered by tests

for file in files.iter().progress_with(pb.clone()) {
let file_name = file.file_name().ok_or_else(|| {
let file = file.display();
anyhow!("Failed to get file name from path: {file}")
})?;
let pb = ProgressBar::new(files.len() as u64);
pb.set_style(ProgressStyle::with_template(
"{bar:60} ({pos}/{len}, ETA {eta})",
)?);

Check warning on line 42 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L39-L42

Added lines #L39 - L42 were not covered by tests

let crate_name = file_name.to_str().ok_or_else(|| {
let file_name = file_name.to_string_lossy();
anyhow!("Failed to convert file name to utf8: {file_name}",)
})?;
for file in files.iter().progress_with(pb.clone()) {
let file_name = file.file_name().ok_or_else(|| {
let file = file.display();
anyhow!("Failed to get file name from path: {file}")
})?;

Check warning on line 48 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L44-L48

Added lines #L44 - L48 were not covered by tests

let path = repo.index_file(crate_name);
if !path.exists() {
pb.suspend(|| println!("skipping file `{crate_name}`"));
continue;
}
let crate_name = file_name.to_str().ok_or_else(|| {
let file_name = file_name.to_string_lossy();
anyhow!("Failed to convert file name to utf8: {file_name}",)
})?;

Check warning on line 53 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L50-L53

Added lines #L50 - L53 were not covered by tests

let contents = std::fs::read_to_string(&path)?;
Handle::current().block_on(storage.sync_index(crate_name, Some(contents)))?;
let path = repo.index_file(crate_name);
if !path.exists() {
pb.suspend(|| println!("skipping file `{crate_name}`"));
continue;

Check warning on line 58 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L55-L58

Added lines #L55 - L58 were not covered by tests
}

println!(
"uploading completed; use `upload-index {}` for an incremental run",
repo.head_oid()?
);
Ok(())
})
.await
let contents = tokio::fs::read_to_string(&path).await?;
storage.sync_index(crate_name, Some(contents)).await?;

Check warning on line 62 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L61-L62

Added lines #L61 - L62 were not covered by tests
}

println!(
"uploading completed; use `upload-index {}` for an incremental run",
repo.head_oid()?

Check warning on line 67 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L65-L67

Added lines #L65 - L67 were not covered by tests
);
Ok(())

Check warning on line 69 in src/bin/crates-admin/upload_index.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/crates-admin/upload_index.rs#L69

Added line #L69 was not covered by tests
}