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!' // replace the 'progress' prefix if this function is invoked via 'progress!'
record record
.target() .target()
.replacen("progress", "crunchy_cli", 1) .replacen("crunchy_cli_core", "crunchy_cli", 1)
.replacen("progress_end", "crunchy_cli", 1), .replacen("progress_end", "crunchy_cli", 1)
.replacen("progress", "crunchy_cli", 1),
format!("{:?}", thread::current().id()) format!("{:?}", thread::current().id())
.replace("ThreadId(", "") .replace("ThreadId(", "")
.replace(')', ""), .replace(')', ""),

View file

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