zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7036644ed2a50e4b10f45b8fce23ce5258e5f58f (tree)
parent 511acc167f4cea39cb780ad93a36dfd0e64e4417
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Fri, 16 Feb 2024 19:28:35 -0700

std.http.Client: remove advisory file lock on fetch

This is not an appropriate place to put this code. It belongs in the
caller's code, if at all.

Diffstat:
Mlib/std/http/Client.zig | 37+++++++++++++++----------------------
1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig @@ -1648,32 +1648,25 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc }); defer req.deinit(); - { // Block to maintain lock of file to attempt to prevent a race condition where another process modifies the file while we are reading it. - // This relies on other processes actually obeying the advisory lock, which is not guaranteed. - if (options.payload == .file) try options.payload.file.lock(.shared); - defer if (options.payload == .file) options.payload.file.unlock(); - - switch (options.payload) { - .string => |str| req.transfer_encoding = .{ .content_length = str.len }, - .file => |file| req.transfer_encoding = .{ .content_length = (try file.stat()).size }, - .none => {}, - } - - try req.send(.{ .raw_uri = options.raw_uri }); + switch (options.payload) { + .string => |str| req.transfer_encoding = .{ .content_length = str.len }, + .file => |file| req.transfer_encoding = .{ .content_length = (try file.stat()).size }, + .none => {}, + } - switch (options.payload) { - .string => |str| try req.writeAll(str), - .file => |file| { - try file.seekTo(0); - var fifo = std.fifo.LinearFifo(u8, .{ .Static = 8192 }).init(); - try fifo.pump(file.reader(), req.writer()); - }, - .none => {}, - } + try req.send(.{ .raw_uri = options.raw_uri }); - try req.finish(); + switch (options.payload) { + .string => |str| try req.writeAll(str), + .file => |file| { + try file.seekTo(0); + var fifo = std.fifo.LinearFifo(u8, .{ .Static = 8192 }).init(); + try fifo.pump(file.reader(), req.writer()); + }, + .none => {}, } + try req.finish(); try req.wait(); var res: FetchResult = .{