Skip to content

Commit 9650526

Browse files
committed
fix: download progress stuck at 99%
1 parent 35d3cbd commit 9650526

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/install.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ pub fn download_tarball(alloc: Allocator, client: *Client, tb_url: []const u8, t
121121

122122
// Convert everything into f64 for less typing in calculating % download and download speed
123123
var dlnow = std.atomic.Value(f32).init(0);
124-
const total_size_double: f64 = @floatFromInt(total_size);
124+
const total_size_d: f64 = @floatFromInt(total_size);
125+
const tarball_size_d: f64 = @floatFromInt(tarball_size);
125126

126-
const progress_thread = try std.Thread.spawn(.{}, download_progress_bar, .{ &dlnow, @as(f64, @floatFromInt(tarball_size)), total_size_double });
127-
while (true) {
127+
const progress_thread = try std.Thread.spawn(.{}, download_progress_bar, .{ &dlnow, tarball_size_d, total_size_d });
128+
while (tarball_size_d + dlnow.load(AtomicOrder.monotonic) <= total_size_d) {
128129
const len = try reader.read(&buff);
129130
if (len == 0) {
130131
break;
@@ -154,7 +155,7 @@ pub fn download_progress_bar(dlnow: *std.atomic.Value(f32), tarball_size: f64, t
154155
const speed = downloaded / 1024 / @as(f64, @floatFromInt(timer.read() / time.ns_per_s));
155156
try stderr_writer.print("\x1b[G\x1b[0K\t\x1b[33m{s}\x1b[0m{s} {d}% {d:.1}KB/s", .{ progress_bar[0 .. newbars * 3], progress_bar[newbars * 3 ..], pcnt_complete, speed });
156157

157-
if (downloaded + tarball_size == total_size) break;
158+
if (downloaded + tarball_size >= total_size) break;
158159

159160
std.time.sleep(500 * time.ns_per_ms);
160161
downloaded = dlnow.load(AtomicOrder.monotonic);

0 commit comments

Comments
 (0)