| ... | ... | @@ -485,6 +485,8 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 485 | 485 | }; |
| 486 | 486 | std.mem.sortUnstable(Build.Cache.Path, deduped_paths, SortContext{}, SortContext.lessThan); |
| 487 | 487 | |
| 488 | var cwd_cache: ?[]const u8 = null; |
| 489 | |
| 488 | 490 | for (deduped_paths) |joined_path| { |
| 489 | 491 | var file = joined_path.root_dir.handle.openFile(joined_path.sub_path, .{}) catch |err| { |
| 490 | 492 | log.err("failed to open {}: {s}", .{ joined_path, @errorName(err) }); |
| ... | ... | @@ -506,7 +508,10 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 506 | 508 | |
| 507 | 509 | var file_header = std.tar.output.Header.init(); |
| 508 | 510 | file_header.typeflag = .regular; |
| 509 | | try file_header.setPath(joined_path.root_dir.path orelse ".", joined_path.sub_path); |
| 511 | try file_header.setPath( |
| 512 | joined_path.root_dir.path orelse try memoizedCwd(arena, &cwd_cache), |
| 513 | joined_path.sub_path, |
| 514 | ); |
| 510 | 515 | try file_header.setSize(stat.size); |
| 511 | 516 | try file_header.updateChecksum(); |
| 512 | 517 | try w.writeAll(std.mem.asBytes(&file_header)); |
| ... | ... | @@ -519,6 +524,13 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 519 | 524 | try response.end(); |
| 520 | 525 | } |
| 521 | 526 | |
| 527 | fn memoizedCwd(arena: Allocator, opt_ptr: *?[]const u8) ![]const u8 { |
| 528 | if (opt_ptr.*) |cached| return cached; |
| 529 | const result = try std.process.getCwdAlloc(arena); |
| 530 | opt_ptr.* = result; |
| 531 | return result; |
| 532 | } |
| 533 | |
| 522 | 534 | const cache_control_header: std.http.Header = .{ |
| 523 | 535 | .name = "cache-control", |
| 524 | 536 | .value = "max-age=0, must-revalidate", |