From f755e0aeec74cea357c9b20faa10e95a040e4066 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Mon, 13 May 2024 01:26:18 +0500 Subject: [PATCH] Move tmp file to original --- src/hosts.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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; + } + }; +}