mirror of
https://github.com/ziglang/zig.git
synced 2025-12-09 15:53:08 +00:00
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.
This commit is contained in:
parent
511acc167f
commit
7036644ed2
@ -1648,32 +1648,25 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc
|
|||||||
});
|
});
|
||||||
defer req.deinit();
|
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.
|
switch (options.payload) {
|
||||||
// This relies on other processes actually obeying the advisory lock, which is not guaranteed.
|
.string => |str| req.transfer_encoding = .{ .content_length = str.len },
|
||||||
if (options.payload == .file) try options.payload.file.lock(.shared);
|
.file => |file| req.transfer_encoding = .{ .content_length = (try file.stat()).size },
|
||||||
defer if (options.payload == .file) options.payload.file.unlock();
|
.none => {},
|
||||||
|
|
||||||
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| 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.send(.{ .raw_uri = options.raw_uri });
|
||||||
|
|
||||||
|
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();
|
try req.wait();
|
||||||
|
|
||||||
var res: FetchResult = .{
|
var res: FetchResult = .{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user