Fix progress showing kb for downloading packages instead of count (#24700)

- show bytes for upgrading bun
- show no unit for other progress bars

Fix for issue introduced in #24266
This commit is contained in:
pfg
2025-11-13 19:29:16 -08:00
committed by GitHub
parent 21d582a3cd
commit d8ee26509c
3 changed files with 11 additions and 8 deletions

View File

@@ -71,7 +71,7 @@ pub const Node = struct {
context: *Progress,
parent: ?*Node,
name: []const u8,
unit: []const u8 = "",
unit: enum { none, files, bytes } = .none,
/// Must be handled atomically to be thread-safe.
recently_updated_child: ?*Node = null,
/// Must be handled atomically to be thread-safe. 0 means null.
@@ -326,16 +326,18 @@ fn refreshWithHeldLock(self: *Progress) void {
}
if (eti > 0) {
if (need_ellipse) self.bufWrite(&end, " ", .{});
switch (node.unit.len == 0) {
true => self.bufWrite(&end, "[{Bi:.2}/{Bi:.2}] ", .{ current_item, eti }),
false => self.bufWrite(&end, "[{d}/{d}{s}] ", .{ current_item, eti, node.unit }),
switch (node.unit) {
.none => self.bufWrite(&end, "[{d}/{d}] ", .{ current_item, eti }),
.files => self.bufWrite(&end, "[{d}/{d} files] ", .{ current_item, eti }),
.bytes => self.bufWrite(&end, "[{Bi:.2}/{Bi:.2}] ", .{ current_item, eti }),
}
need_ellipse = false;
} else if (completed_items != 0) {
if (need_ellipse) self.bufWrite(&end, " ", .{});
switch (node.unit.len == 0) {
true => self.bufWrite(&end, "[{Bi:.2}] ", .{current_item}),
false => self.bufWrite(&end, "[{d}{s}] ", .{ current_item, node.unit }),
switch (node.unit) {
.none => self.bufWrite(&end, "[{d}] ", .{current_item}),
.files => self.bufWrite(&end, "[{d} files] ", .{current_item}),
.bytes => self.bufWrite(&end, "[{Bi:.2}] ", .{current_item}),
}
need_ellipse = false;
}

View File

@@ -1638,7 +1638,7 @@ pub const PackCommand = struct {
progress = .{};
progress.supports_ansi_escape_codes = Output.enable_ansi_colors_stderr;
node = progress.start("", pack_queue.count() + bundled_pack_queue.count() + 1);
node.unit = " files";
node.unit = .files;
}
defer if (log_level.showProgress()) node.end();

View File

@@ -422,6 +422,7 @@ pub const UpgradeCommand = struct {
{
var refresher = Progress{};
var progress = refresher.start("Downloading", version.size);
progress.unit = .bytes;
refresher.refresh();
var async_http = try ctx.allocator.create(HTTP.AsyncHTTP);
var zip_file_buffer = try ctx.allocator.create(MutableString);