Skip to content

Commit 6a3e88d

Browse files
committed
chore: Correct potential panic should the installer time travel into the past
Signed-off-by: Daniel Silverstone (WSL2) <[email protected]>
1 parent 188b8d0 commit 6a3e88d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/cli/download_tracker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl DownloadTracker {
118118
match self.last_sec {
119119
None => self.last_sec = Some(current_time),
120120
Some(prev) => {
121-
let elapsed = current_time - prev;
121+
let elapsed = current_time.saturating_duration_since(prev);
122122
if elapsed >= Duration::from_secs(1) {
123123
if self.display_progress {
124124
self.display();
@@ -166,7 +166,7 @@ impl DownloadTracker {
166166
let len = self.downloaded_last_few_secs.len();
167167
let speed = if len > 0 { sum / len } else { 0 };
168168
let speed_h = Size::new(speed, unit, UnitMode::Rate);
169-
let elapsed_h = start_sec.elapsed();
169+
let elapsed_h = Instant::now().saturating_duration_since(start_sec);
170170

171171
// First, move to the start of the current line and clear it.
172172
let _ = self.term.carriage_return();

src/diskio/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ pub fn perform(item: &mut Item) {
151151
Kind::Directory => create_dir(&item.full_path),
152152
Kind::File(ref contents) => write_file(&item.full_path, &contents, item.mode),
153153
};
154-
item.finish = item.start.map(|s| s.elapsed());
154+
item.finish = item
155+
.start
156+
.map(|s| Instant::now().saturating_duration_since(s));
155157
}
156158

157159
#[allow(unused_variables)]

0 commit comments

Comments
 (0)