diff --git a/src/hosts.zig b/src/hosts.zig index 041528b..8748e9a 100644 --- a/src/hosts.zig +++ b/src/hosts.zig @@ -3,7 +3,7 @@ const util = @import("util.zig"); const hosts_header = "# local-etc-hosts-updater"; -const FILE_LINE_BUFF_SIZE = 50; +const FILE_LINE_BUFF_SIZE = 100; pub fn update_hosts(ip: util.IP) !void { try create_tmp_hosts(ip); @@ -107,4 +107,17 @@ fn create_tmp_hosts(ip: util.IP) !void { } } -fn move_tmp_hosts() !void {} +fn move_tmp_hosts() !void { + var target_hosts = try std.fs.createFileAbsoluteZ(try util.getenv("OLD_HOSTS_PATH"), .{ .lock = .exclusive }); + defer target_hosts.close(); + const target_writer = target_hosts.writer(); + var tmp_hosts = try std.fs.openFileAbsoluteZ(try util.getenv("TMP_HOSTS_PATH"), .{}); + defer tmp_hosts.close(); + const source_reader = tmp_hosts.reader(); + + source_reader.streamUntilDelimiter(target_writer, 0x00, null) catch |err| { + if (err != error.EndOfStream) { + return err; + } + }; +}