| ... | @@ -114,6 +114,7 @@ pub const JobQueue = struct { | ... | @@ -114,6 +114,7 @@ pub const JobQueue = struct { |
| 114 | /// field contains references to all of them. | 114 | /// field contains references to all of them. |
| 115 | /// Protected by `mutex`. | 115 | /// Protected by `mutex`. |
| 116 | all_fetches: std.ArrayList(*Fetch) = .empty, | 116 | all_fetches: std.ArrayList(*Fetch) = .empty, |
| | 117 | prog_node: std.Progress.Node, |
| 117 | | 118 | |
| 118 | http_client: *std.http.Client, | 119 | http_client: *std.http.Client, |
| 119 | /// This tracks `Fetch` tasks as well as recompression tasks. | 120 | /// This tracks `Fetch` tasks as well as recompression tasks. |
| ... | @@ -302,12 +303,15 @@ pub const JobQueue = struct { | ... | @@ -302,12 +303,15 @@ pub const JobQueue = struct { |
| 302 | } | 303 | } |
| 303 | | 304 | |
| 304 | fn recompress(jq: *JobQueue, package_hash: Package.Hash) Io.Cancelable!void { | 305 | 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; |
| 306 | const dest_path: Cache.Path = .{ | 312 | const dest_path: Cache.Path = .{ |
| 307 | .root_dir = jq.global_cache, | 313 | .root_dir = jq.global_cache, |
| 308 | .sub_path = std.fmt.bufPrint(&dest_sub_path_buffer, "p/{s}.tar.gz", .{ | 314 | .sub_path = std.fmt.bufPrint(&dest_sub_path_buf, "p/{s}.tar.gz", .{pkg_hash_slice}) catch unreachable, |
| 309 | package_hash.toSlice(), | | |
| 310 | }) catch unreachable, | | |
| 311 | }; | 315 | }; |
| 312 | | 316 | |
| 313 | const gpa = jq.http_client.allocator; | 317 | const gpa = jq.http_client.allocator; |
| ... | @@ -316,7 +320,7 @@ pub const JobQueue = struct { | ... | @@ -316,7 +320,7 @@ pub const JobQueue = struct { |
| 316 | defer arena_instance.deinit(); | 320 | defer arena_instance.deinit(); |
| 317 | const arena = arena_instance.allocator(); | 321 | const arena = arena_instance.allocator(); |
| 318 | | 322 | |
| 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) { |
| 320 | error.Canceled => |e| return e, | 324 | error.Canceled => |e| return e, |
| 321 | error.ReadFailed => comptime unreachable, | 325 | error.ReadFailed => comptime unreachable, |
| 322 | error.WriteFailed => comptime unreachable, | 326 | error.WriteFailed => comptime unreachable, |
| ... | @@ -324,7 +328,13 @@ pub const JobQueue = struct { | ... | @@ -324,7 +328,13 @@ pub const JobQueue = struct { |
| 324 | }; | 328 | }; |
| 325 | } | 329 | } |
| 326 | | 330 | |
| 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 { |
| 328 | const gpa = jq.http_client.allocator; | 338 | const gpa = jq.http_client.allocator; |
| 329 | const io = jq.io; | 339 | const io = jq.io; |
| 330 | | 340 | |
| ... | @@ -337,7 +347,7 @@ pub const JobQueue = struct { | ... | @@ -337,7 +347,7 @@ pub const JobQueue = struct { |
| 337 | var scanned_files: std.ArrayList([]const u8) = .empty; | 347 | var scanned_files: std.ArrayList([]const u8) = .empty; |
| 338 | defer scanned_files.deinit(gpa); | 348 | defer scanned_files.deinit(gpa); |
| 339 | | 349 | |
| 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 }); |
| 341 | defer pkg_dir.close(io); | 351 | defer pkg_dir.close(io); |
| 342 | | 352 | |
| 343 | { | 353 | { |
| ... | @@ -359,6 +369,8 @@ pub const JobQueue = struct { | ... | @@ -359,6 +369,8 @@ pub const JobQueue = struct { |
| 359 | std.mem.sortUnstable([]const u8, scanned_files.items, {}, stringCmp); | 369 | std.mem.sortUnstable([]const u8, scanned_files.items, {}, stringCmp); |
| 360 | } | 370 | } |
| 361 | | 371 | |
| | 372 | prog_node.setEstimatedTotalItems(scanned_files.items.len); |
| | 373 | |
| 362 | var atomic_file = try dest_path.root_dir.handle.createFileAtomic(io, dest_path.sub_path, .{ | 374 | var atomic_file = try dest_path.root_dir.handle.createFileAtomic(io, dest_path.sub_path, .{ |
| 363 | .make_path = true, | 375 | .make_path = true, |
| 364 | .replace = true, | 376 | .replace = true, |
| ... | @@ -374,7 +386,7 @@ pub const JobQueue = struct { | ... | @@ -374,7 +386,7 @@ pub const JobQueue = struct { |
| 374 | }; | 386 | }; |
| 375 | | 387 | |
| 376 | var archiver: std.tar.Writer = .{ .underlying_writer = &compress.writer }; | 388 | var archiver: std.tar.Writer = .{ .underlying_writer = &compress.writer }; |
| 377 | archiver.prefix = package_hash; | 389 | archiver.prefix = pkg_hash_slice; |
| 378 | | 390 | |
| 379 | var file_read_buffer: [4096]u8 = undefined; | 391 | var file_read_buffer: [4096]u8 = undefined; |
| 380 | | 392 | |
| ... | @@ -387,6 +399,7 @@ pub const JobQueue = struct { | ... | @@ -387,6 +399,7 @@ pub const JobQueue = struct { |
| 387 | error.WriteFailed => return file_writer.err.?, | 399 | error.WriteFailed => return file_writer.err.?, |
| 388 | else => |e| return e, | 400 | else => |e| return e, |
| 389 | }; | 401 | }; |
| | 402 | prog_node.completeOne(); |
| 390 | } | 403 | } |
| 391 | | 404 | |
| 392 | // intentionally omitting the pointless trailer | 405 | // intentionally omitting the pointless trailer |
| ... | @@ -2259,6 +2272,7 @@ const TestFetchBuilder = struct { | ... | @@ -2259,6 +2272,7 @@ const TestFetchBuilder = struct { |
| 2259 | .read_only = false, | 2272 | .read_only = false, |
| 2260 | .debug_hash = false, | 2273 | .debug_hash = false, |
| 2261 | .mode = .needed, | 2274 | .mode = .needed, |
| | 2275 | .prog_node = std.Progress.Node.none, |
| 2262 | }; | 2276 | }; |
| 2263 | | 2277 | |
| 2264 | self.fetch = .{ | 2278 | self.fetch = .{ |