Skip to content

Commit

Permalink
[Turbopack] update total size when reached (#71354)
Browse files Browse the repository at this point in the history
### What?

When loading a trace file and that increases in size while reading it,
update the info about the total size before reaching 100%.
  • Loading branch information
sokra authored Oct 18, 2024
1 parent 505f850 commit c82f8e6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions turbopack/crates/turbopack-trace-server/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ impl TraceFile {
Self::Unloaded => unreachable!(),
}
}

fn size(&mut self) -> io::Result<u64> {
match self {
Self::Raw(file) => file.metadata().map(|m| m.len()),
Self::Zstd(decoder) => decoder.get_mut().get_ref().metadata().map(|m| m.len()),
Self::Gz(decoder) => decoder.get_mut().get_ref().metadata().map(|m| m.len()),
Self::Unloaded => unreachable!(),
}
}
}

pub struct TraceReader {
Expand Down Expand Up @@ -189,6 +198,9 @@ impl TraceReader {
let new_mbs = current_read / (97 * 1024 * 1024);
if old_mbs != new_mbs {
let pos = file.stream_position().unwrap_or(current_read);
if pos > *total {
*total = file.size().unwrap_or(pos);
}
*total = (*total).max(pos);
let percentage = pos * 100 / *total;
let read = pos / (1024 * 1024);
Expand Down

0 comments on commit c82f8e6

Please sign in to comment.