Merge branch 'master' into fix/rework-download

This commit is contained in:
ByteDream 2023-01-03 01:39:30 +01:00 committed by GitHub
commit 83bd71916c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -75,8 +75,9 @@ impl CliLogger {
// replace the 'progress' prefix if this function is invoked via 'progress!'
record
.target()
.replacen("progress", "crunchy_cli", 1)
.replacen("progress_end", "crunchy_cli", 1),
.replacen("crunchy_cli_core", "crunchy_cli", 1)
.replacen("progress_end", "crunchy_cli", 1)
.replacen("progress", "crunchy_cli", 1),
format!("{:?}", thread::current().id())
.replace("ThreadId(", "")
.replace(')', ""),

View file

@ -74,6 +74,7 @@ pub async fn download_segments(
let thread_client = client.clone();
let thread_sender = sender.clone();
let thread_segments = segs.remove(0);
let thread_count = count.clone();
join_set.spawn(async move {
let after_download_sender = thread_sender.clone();
@ -108,16 +109,24 @@ pub async fn download_segments(
};
buf = VariantSegment::decrypt(buf.borrow_mut(), segment.key)?.to_vec();
let mut c = thread_count.lock().unwrap();
debug!(
"Downloaded and decrypted segment {} ({})",
"Downloaded and decrypted segment [{}/{} {:.2}%] {}",
num + (i * cpus),
total_segments,
((*c + 1) as f64 / total_segments as f64) * 100f64,
segment.url
);
thread_sender.send((num as i32 + (i * cpus) as i32, buf))?;
*c += 1;
}
Ok(())
};
let result = download().await;
if result.is_err() {
after_download_sender.send((-1 as i32, vec![]))?;