authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-05 16:46:20-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-05 16:50:41-08:00
log1f65e7cccc3124ce2fa9a5e8107c32367a39ec29
treeb93ddf97b0ccb7607b36a9fd30015a59919eeea5
parent7246eee1e706b142abf8183e960fd692fde52bb0

fetch: recompress task integrates with std.Progress


2 files changed, 24 insertions(+), 8 deletions(-)

src/Package/Fetch.zig+22-8
......@@ -114,6 +114,7 @@ pub const JobQueue = struct {
114114 /// field contains references to all of them.
115115 /// Protected by `mutex`.
116116 all_fetches: std.ArrayList(*Fetch) = .empty,
117 prog_node: std.Progress.Node,
117118
118119 http_client: *std.http.Client,
119120 /// This tracks `Fetch` tasks as well as recompression tasks.
......@@ -302,12 +303,15 @@ pub const JobQueue = struct {
302303 }
303304
304305 fn recompress(jq: *JobQueue, package_hash: Package.Hash) Io.Cancelable!void {
305 var dest_sub_path_buffer: ["p/".len + Package.Hash.max_len + ".tar.gz".len]u8 = undefined;
306 const pkg_hash_slice = package_hash.toSlice();
307
308 const prog_node = jq.prog_node.startFmt(0, "recompress {s}", .{pkg_hash_slice});
309 defer prog_node.end();
310
311 var dest_sub_path_buf: ["p/".len + Package.Hash.max_len + ".tar.gz".len]u8 = undefined;
306312 const dest_path: Cache.Path = .{
307313 .root_dir = jq.global_cache,
308 .sub_path = std.fmt.bufPrint(&dest_sub_path_buffer, "p/{s}.tar.gz", .{
309 package_hash.toSlice(),
310 }) catch unreachable,
314 .sub_path = std.fmt.bufPrint(&dest_sub_path_buf, "p/{s}.tar.gz", .{pkg_hash_slice}) catch unreachable,
311315 };
312316
313317 const gpa = jq.http_client.allocator;
......@@ -316,7 +320,7 @@ pub const JobQueue = struct {
316320 defer arena_instance.deinit();
317321 const arena = arena_instance.allocator();
318322
319 recompressFallible(jq, arena, dest_path, package_hash.toSlice()) catch |err| switch (err) {
323 recompressFallible(jq, arena, dest_path, pkg_hash_slice, prog_node) catch |err| switch (err) {
320324 error.Canceled => |e| return e,
321325 error.ReadFailed => comptime unreachable,
322326 error.WriteFailed => comptime unreachable,
......@@ -324,7 +328,13 @@ pub const JobQueue = struct {
324328 };
325329 }
326330
327 fn recompressFallible(jq: *JobQueue, arena: Allocator, dest_path: Cache.Path, package_hash: []const u8) !void {
331 fn recompressFallible(
332 jq: *JobQueue,
333 arena: Allocator,
334 dest_path: Cache.Path,
335 pkg_hash_slice: []const u8,
336 prog_node: std.Progress.Node,
337 ) !void {
328338 const gpa = jq.http_client.allocator;
329339 const io = jq.io;
330340
......@@ -337,7 +347,7 @@ pub const JobQueue = struct {
337347 var scanned_files: std.ArrayList([]const u8) = .empty;
338348 defer scanned_files.deinit(gpa);
339349
340 var pkg_dir = try jq.root_pkg_path.openDir(io, package_hash, .{ .iterate = true });
350 var pkg_dir = try jq.root_pkg_path.openDir(io, pkg_hash_slice, .{ .iterate = true });
341351 defer pkg_dir.close(io);
342352
343353 {
......@@ -359,6 +369,8 @@ pub const JobQueue = struct {
359369 std.mem.sortUnstable([]const u8, scanned_files.items, {}, stringCmp);
360370 }
361371
372 prog_node.setEstimatedTotalItems(scanned_files.items.len);
373
362374 var atomic_file = try dest_path.root_dir.handle.createFileAtomic(io, dest_path.sub_path, .{
363375 .make_path = true,
364376 .replace = true,
......@@ -374,7 +386,7 @@ pub const JobQueue = struct {
374386 };
375387
376388 var archiver: std.tar.Writer = .{ .underlying_writer = &compress.writer };
377 archiver.prefix = package_hash;
389 archiver.prefix = pkg_hash_slice;
378390
379391 var file_read_buffer: [4096]u8 = undefined;
380392
......@@ -387,6 +399,7 @@ pub const JobQueue = struct {
387399 error.WriteFailed => return file_writer.err.?,
388400 else => |e| return e,
389401 };
402 prog_node.completeOne();
390403 }
391404
392405 // intentionally omitting the pointless trailer
......@@ -2259,6 +2272,7 @@ const TestFetchBuilder = struct {
22592272 .read_only = false,
22602273 .debug_hash = false,
22612274 .mode = .needed,
2275 .prog_node = std.Progress.Node.none,
22622276 };
22632277
22642278 self.fetch = .{
src/main.zig+2
......@@ -5246,6 +5246,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
52465246 .debug_hash = false,
52475247 .unlazy_set = unlazy_set,
52485248 .mode = fetch_mode,
5249 .prog_node = fetch_prog_node,
52495250 };
52505251 defer job_queue.deinit();
52515252
......@@ -7026,6 +7027,7 @@ fn cmdFetch(
70267027 .read_only = false,
70277028 .debug_hash = debug_hash,
70287029 .mode = .all,
7030 .prog_node = root_prog_node,
70297031 };
70307032 defer job_queue.deinit();
70317033