| author | |
| committer | |
| log | ab3a947bef0b167665068ab40232609e4d9b656c |
| tree | 43a05171c80cea016cb603f76c72526530dc86e0 |
| parent | 81b0d14e2ba43732c80a259b578997f167c23cdd |
6 files changed, 26 insertions(+), 28 deletions(-)
lib/std/Build/Cache.zig+7-14| ... | ... | @@ -335,7 +335,6 @@ pub const Manifest = struct { |
| 335 | 335 | manifest_create: fs.File.OpenError, |
| 336 | 336 | manifest_read: fs.File.ReadError, |
| 337 | 337 | manifest_lock: fs.File.LockError, |
| 338 | manifest_seek: fs.File.SeekError, | |
| 339 | 338 | file_open: FileOp, |
| 340 | 339 | file_stat: FileOp, |
| 341 | 340 | file_read: FileOp, |
| ... | ... | @@ -609,12 +608,6 @@ pub const Manifest = struct { |
| 609 | 608 | var file = self.files.pop().?; |
| 610 | 609 | file.key.deinit(self.cache.gpa); |
| 611 | 610 | } |
| 612 | // Also, seek the file back to the start. | |
| 613 | self.manifest_file.?.seekTo(0) catch |err| { | |
| 614 | self.diagnostic = .{ .manifest_seek = err }; | |
| 615 | return error.CacheCheckFailed; | |
| 616 | }; | |
| 617 | ||
| 618 | 611 | switch (try self.hitWithCurrentLock()) { |
| 619 | 612 | .hit => break :hit, |
| 620 | 613 | .miss => |m| break :digests m.file_digests_populated, |
| ... | ... | @@ -659,9 +652,8 @@ pub const Manifest = struct { |
| 659 | 652 | return true; |
| 660 | 653 | } |
| 661 | 654 | |
| 662 | /// Assumes that `self.hash.hasher` has been updated only with the original digest, that | |
| 663 | /// `self.files` contains only the original input files, and that `self.manifest_file.?` is | |
| 664 | /// seeked to the start of the file. | |
| 655 | /// Assumes that `self.hash.hasher` has been updated only with the original digest and that | |
| 656 | /// `self.files` contains only the original input files. | |
| 665 | 657 | fn hitWithCurrentLock(self: *Manifest) HitError!union(enum) { |
| 666 | 658 | hit, |
| 667 | 659 | miss: struct { |
| ... | ... | @@ -670,12 +662,13 @@ pub const Manifest = struct { |
| 670 | 662 | } { |
| 671 | 663 | const gpa = self.cache.gpa; |
| 672 | 664 | const input_file_count = self.files.entries.len; |
| 673 | ||
| 674 | const file_contents = self.manifest_file.?.reader().readAllAlloc(gpa, manifest_file_size_max) catch |err| switch (err) { | |
| 665 | var manifest_reader = self.manifest_file.?.reader(); // Reads positionally from zero. | |
| 666 | const limit: std.io.Reader.Limit = .limited(manifest_file_size_max); | |
| 667 | const file_contents = manifest_reader.interface().readRemainingAlloc(gpa, limit) catch |err| switch (err) { | |
| 675 | 668 | error.OutOfMemory => return error.OutOfMemory, |
| 676 | 669 | error.StreamTooLong => return error.OutOfMemory, |
| 677 | else => |e| { | |
| 678 | self.diagnostic = .{ .manifest_read = e }; | |
| 670 | error.ReadFailed => { | |
| 671 | self.diagnostic = .{ .manifest_read = manifest_reader.err.? }; | |
| 679 | 672 | return error.CacheCheckFailed; |
| 680 | 673 | }, |
| 681 | 674 | }; |
lib/std/Build/Fuzz/WebServer.zig+4-6| ... | ... | @@ -109,7 +109,7 @@ fn accept(ws: *WebServer, connection: std.net.Server.Connection) void { |
| 109 | 109 | var server: std.http.Server = .init(&br, &bw); |
| 110 | 110 | var web_socket: std.http.WebSocket = undefined; |
| 111 | 111 | var ws_recv_buffer: [0x4000]u8 align(4) = undefined; |
| 112 | while (server.state == .ready) { | |
| 112 | while (server.reader.state == .ready) { | |
| 113 | 113 | var request = server.receiveHead() catch |err| switch (err) { |
| 114 | 114 | error.HttpConnectionClosing => return, |
| 115 | 115 | else => { |
| ... | ... | @@ -476,7 +476,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 476 | 476 | defer arena_instance.deinit(); |
| 477 | 477 | const arena = arena_instance.allocator(); |
| 478 | 478 | |
| 479 | var response = try request.respondStreaming(.{ | |
| 479 | var body_writer = try request.respondStreaming(.{ | |
| 480 | 480 | .respond_options = .{ |
| 481 | 481 | .extra_headers = &.{ |
| 482 | 482 | .{ .name = "content-type", .value = "application/x-tar" }, |
| ... | ... | @@ -517,7 +517,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 517 | 517 | |
| 518 | 518 | var cwd_cache: ?[]const u8 = null; |
| 519 | 519 | |
| 520 | var response_writer = response.writer().unbuffered(); | |
| 520 | var response_writer = body_writer.interface().unbuffered(); | |
| 521 | 521 | var archiver: std.tar.Writer = .{ .underlying_writer = &response_writer }; |
| 522 | 522 | |
| 523 | 523 | for (deduped_paths) |joined_path| { |
| ... | ... | @@ -531,9 +531,7 @@ fn serveSourcesTar(ws: *WebServer, request: *std.http.Server.Request) !void { |
| 531 | 531 | try archiver.writeFile(joined_path.sub_path, file, try file.stat()); |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | // intentionally omitting the pointless trailer | |
| 535 | //try archiver.finish(); | |
| 536 | try response.end(); | |
| 534 | try body_writer.end(); | |
| 537 | 535 | } |
| 538 | 536 | |
| 539 | 537 | fn memoizedCwd(arena: Allocator, opt_ptr: *?[]const u8) ![]const u8 { |
lib/std/Build/Step.zig+1-1| ... | ... | @@ -812,7 +812,7 @@ fn failWithCacheError(s: *Step, man: *const Build.Cache.Manifest, err: Build.Cac |
| 812 | 812 | switch (err) { |
| 813 | 813 | error.CacheCheckFailed => switch (man.diagnostic) { |
| 814 | 814 | .none => unreachable, |
| 815 | .manifest_create, .manifest_read, .manifest_lock, .manifest_seek => |e| return s.fail("failed to check cache: {s} {s}", .{ | |
| 815 | .manifest_create, .manifest_read, .manifest_lock => |e| return s.fail("failed to check cache: {s} {s}", .{ | |
| 816 | 816 | @tagName(man.diagnostic), @errorName(e), |
| 817 | 817 | }), |
| 818 | 818 | .file_open, .file_stat, .file_read, .file_hash => |op| { |
lib/std/http.zig+2| ... | ... | @@ -772,6 +772,7 @@ pub const BodyWriter = struct { |
| 772 | 772 | /// * `endChunked` |
| 773 | 773 | pub fn endUnflushed(w: *BodyWriter) WriteError!void { |
| 774 | 774 | switch (w.state) { |
| 775 | .end => unreachable, | |
| 775 | 776 | .content_length => |len| { |
| 776 | 777 | assert(len == 0); // Trips when end() called before all bytes written. |
| 777 | 778 | w.state = .end; |
| ... | ... | @@ -1033,6 +1034,7 @@ pub const BodyWriter = struct { |
| 1033 | 1034 | .writeSplat = chunkedWriteSplat, |
| 1034 | 1035 | .writeFile = chunkedWriteFile, |
| 1035 | 1036 | }, |
| 1037 | .end => unreachable, | |
| 1036 | 1038 | }, |
| 1037 | 1039 | }; |
| 1038 | 1040 | } |
lib/std/http/Server.zig+4-4| ... | ... | @@ -11,7 +11,6 @@ const Server = @This(); |
| 11 | 11 | |
| 12 | 12 | /// Data from the HTTP server to the HTTP client. |
| 13 | 13 | out: *std.io.BufferedWriter, |
| 14 | /// Internal state managed by this abstraction. | |
| 15 | 14 | reader: http.Reader, |
| 16 | 15 | |
| 17 | 16 | /// Initialize an HTTP server that can respond to multiple requests on the same |
| ... | ... | @@ -26,6 +25,7 @@ pub fn init(in: *std.io.BufferedReader, out: *std.io.BufferedWriter) Server { |
| 26 | 25 | .reader = .{ |
| 27 | 26 | .in = in, |
| 28 | 27 | .state = .ready, |
| 28 | .body_state = undefined, | |
| 29 | 29 | }, |
| 30 | 30 | .out = out, |
| 31 | 31 | }; |
| ... | ... | @@ -39,7 +39,7 @@ pub const ReceiveHeadError = http.Reader.HeadError || error{ |
| 39 | 39 | HttpHeadersInvalid, |
| 40 | 40 | }; |
| 41 | 41 | |
| 42 | pub fn receiveHead(s: *Server) http.Reader.HeadError!Request { | |
| 42 | pub fn receiveHead(s: *Server) ReceiveHeadError!Request { | |
| 43 | 43 | try s.reader.receiveHead(); |
| 44 | 44 | return .{ |
| 45 | 45 | .server = s, |
| ... | ... | @@ -490,13 +490,13 @@ pub const Request = struct { |
| 490 | 490 | |
| 491 | 491 | return .{ |
| 492 | 492 | .http_protocol_output = request.server.out, |
| 493 | .transfer_encoding = if (o.transfer_encoding) |te| switch (te) { | |
| 493 | .state = if (o.transfer_encoding) |te| switch (te) { | |
| 494 | 494 | .chunked => .{ .chunked = .init }, |
| 495 | 495 | .none => .none, |
| 496 | 496 | } else if (options.content_length) |len| .{ |
| 497 | 497 | .content_length = len, |
| 498 | 498 | } else .{ .chunked = .init }, |
| 499 | .elide_body = elide_body, | |
| 499 | .elide = elide_body, | |
| 500 | 500 | }; |
| 501 | 501 | } |
| 502 | 502 |
lib/std/tar/Writer.zig+8-3| ... | ... | @@ -50,9 +50,14 @@ pub fn writeFile( |
| 50 | 50 | try w.setPath(&header, sub_path); |
| 51 | 51 | try header.setSize(stat.size); |
| 52 | 52 | try header.setMtime(mtime); |
| 53 | try header.write(w.underlying_writer); | |
| 54 | ||
| 55 | try w.underlying_writer.writeFileAll(file, .{ .limit = .limited(stat.size) }); | |
| 53 | try header.updateChecksum(); | |
| 54 | ||
| 55 | var vec: [1][]const u8 = .{@ptrCast((&header)[0..1])}; | |
| 56 | try w.underlying_writer.writeFileAll(file, .{ | |
| 57 | .limit = .limited(stat.size), | |
| 58 | .headers_and_trailers = &vec, | |
| 59 | .headers_len = 1, | |
| 60 | }); | |
| 56 | 61 | try w.writePadding(stat.size); |
| 57 | 62 | } |
| 58 | 63 |