mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
fix: import_backup_stream: Fix progress stucking at 0
Fix the progress calculation, before `total_size.checked_div(file_size)` was giving 0 if `total_size < file_size`.
This commit is contained in:
@@ -312,8 +312,8 @@ async fn import_backup_stream_inner<R: tokio::io::AsyncRead + Unpin>(
|
|||||||
let mut blobs = Vec::new();
|
let mut blobs = Vec::new();
|
||||||
// We already emitted ImexProgress(10) above
|
// We already emitted ImexProgress(10) above
|
||||||
let mut last_progress = 10;
|
let mut last_progress = 10;
|
||||||
const PROGRESS_MIGRATIONS: u64 = 999;
|
const PROGRESS_MIGRATIONS: u128 = 999;
|
||||||
let mut total_size = 0;
|
let mut total_size: u64 = 0;
|
||||||
let mut res: Result<()> = loop {
|
let mut res: Result<()> = loop {
|
||||||
let mut f = match entries.try_next().await {
|
let mut f = match entries.try_next().await {
|
||||||
Ok(Some(f)) => f,
|
Ok(Some(f)) => f,
|
||||||
@@ -324,9 +324,10 @@ async fn import_backup_stream_inner<R: tokio::io::AsyncRead + Unpin>(
|
|||||||
Ok(size) => size,
|
Ok(size) => size,
|
||||||
Err(e) => break Err(e).context("Failed to get entry size"),
|
Err(e) => break Err(e).context("Failed to get entry size"),
|
||||||
};
|
};
|
||||||
|
let max = PROGRESS_MIGRATIONS - 1;
|
||||||
let progress = std::cmp::min(
|
let progress = std::cmp::min(
|
||||||
1000 * total_size.checked_div(file_size).unwrap_or_default(),
|
max * u128::from(total_size) / std::cmp::max(u128::from(file_size), 1),
|
||||||
PROGRESS_MIGRATIONS - 1,
|
max,
|
||||||
);
|
);
|
||||||
if progress > last_progress {
|
if progress > last_progress {
|
||||||
context.emit_event(EventType::ImexProgress(progress as usize));
|
context.emit_event(EventType::ImexProgress(progress as usize));
|
||||||
|
|||||||
Reference in New Issue
Block a user