| ... | @@ -1648,32 +1648,25 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc | ... | @@ -1648,32 +1648,25 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc |
| 1648 | }); | 1648 | }); |
| 1649 | defer req.deinit(); | 1649 | defer req.deinit(); |
| 1650 | | 1650 | |
| 1651 | { // Block to maintain lock of file to attempt to prevent a race condition where another process modifies the file while we are reading it. | 1651 | switch (options.payload) { |
| 1652 | // This relies on other processes actually obeying the advisory lock, which is not guaranteed. | 1652 | .string => |str| req.transfer_encoding = .{ .content_length = str.len }, |
| 1653 | if (options.payload == .file) try options.payload.file.lock(.shared); | 1653 | .file => |file| req.transfer_encoding = .{ .content_length = (try file.stat()).size }, |
| 1654 | defer if (options.payload == .file) options.payload.file.unlock(); | 1654 | .none => {}, |
| 1655 | | 1655 | } |
| 1656 | switch (options.payload) { | | |
| 1657 | .string => |str| req.transfer_encoding = .{ .content_length = str.len }, | | |
| 1658 | .file => |file| req.transfer_encoding = .{ .content_length = (try file.stat()).size }, | | |
| 1659 | .none => {}, | | |
| 1660 | } | | |
| 1661 | | | |
| 1662 | try req.send(.{ .raw_uri = options.raw_uri }); | | |
| 1663 | | 1656 | |
| 1664 | switch (options.payload) { | 1657 | try req.send(.{ .raw_uri = options.raw_uri }); |
| 1665 | .string => |str| try req.writeAll(str), | | |
| 1666 | .file => |file| { | | |
| 1667 | try file.seekTo(0); | | |
| 1668 | var fifo = std.fifo.LinearFifo(u8, .{ .Static = 8192 }).init(); | | |
| 1669 | try fifo.pump(file.reader(), req.writer()); | | |
| 1670 | }, | | |
| 1671 | .none => {}, | | |
| 1672 | } | | |
| 1673 | | 1658 | |
| 1674 | try req.finish(); | 1659 | switch (options.payload) { |
| | 1660 | .string => |str| try req.writeAll(str), |
| | 1661 | .file => |file| { |
| | 1662 | try file.seekTo(0); |
| | 1663 | var fifo = std.fifo.LinearFifo(u8, .{ .Static = 8192 }).init(); |
| | 1664 | try fifo.pump(file.reader(), req.writer()); |
| | 1665 | }, |
| | 1666 | .none => {}, |
| 1675 | } | 1667 | } |
| 1676 | | 1668 | |
| | 1669 | try req.finish(); |
| 1677 | try req.wait(); | 1670 | try req.wait(); |
| 1678 | | 1671 | |
| 1679 | var res: FetchResult = .{ | 1672 | var res: FetchResult = .{ |