Skip to content

Commit

Permalink
Add progress for DHT update
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Oct 24, 2022
1 parent 67ee33d commit b8dd65e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions iroh/src/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::time::Duration;

use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -162,7 +163,7 @@ async fn add(api: &impl Api, path: &Path, no_wrap: bool, recursive: bool) -> Res
path.display()
);
}
println!("{} Calculating size...", style("[1/2]").bold().dim());
println!("{} Calculating size...", style("[1/3]").bold().dim());

let pb = ProgressBar::new_spinner();
let mut total_size: u64 = 0;
Expand All @@ -184,7 +185,7 @@ async fn add(api: &impl Api, path: &Path, no_wrap: bool, recursive: bool) -> Res

println!(
"{} Importing content {}...",
style("[2/2]").bold().dim(),
style("[2/3]").bold().dim(),
human::format_bytes(total_size)
);

Expand All @@ -209,9 +210,24 @@ async fn add(api: &impl Api, path: &Path, no_wrap: bool, recursive: bool) -> Res
}
}
pb.finish_and_clear();

let pb = ProgressBar::new(100);
let root = root.context("File processing failed")?;
println!("/ipfs/{}", root);
api.provide(root).await?;
let cids = vec![root];
println!(
"{} Providing {} records to DHT ...",
style("[3/3]").bold().dim(),
cids.len(),
);
pb.set_style(ProgressStyle::with_template("[{elapsed_precise}]").unwrap());
pb.inc(0);
tokio::time::sleep(Duration::from_secs(1)).await;
for cid in cids {
api.provide(cid).await?;
pb.inc(1);
}
pb.finish_and_clear();

Ok(())
}

0 comments on commit b8dd65e

Please sign in to comment.