diff --git a/src/consts.zig b/src/consts.zig index e6680c9..0b588dd 100644 --- a/src/consts.zig +++ b/src/consts.zig @@ -1,5 +1,5 @@ pub const ENV_KEY_OLD_HOSTS_PATH = "OLD_HOSTS_PATH"; -pub const ENV_KEY_TMP_HOSTS_PATH = "TMP_HOSTS_PATH"; +pub const TMP_HOSTS_FILE = "tmp_hosts"; pub const ENV_KEY_TARGET_DOMAIN = "TARGET_DOMAIN"; pub const ENV_KEY_SUBDOMAIN_LIST = "SUBDOMAIN_LIST"; diff --git a/src/hosts.zig b/src/hosts.zig index 99a4211..ba3d422 100644 --- a/src/hosts.zig +++ b/src/hosts.zig @@ -108,7 +108,7 @@ fn get_subdomains() !std.mem.SplitIterator(u8, .scalar) { fn create_tmp_hosts(ip: util.IP, domain: util.Domain) !void { var old_hosts = try std.fs.Dir.openFileZ(util.cwd, try util.getenv(util.consts.ENV_KEY_OLD_HOSTS_PATH), .{ .mode = .read_only }); defer old_hosts.close(); - var tmp_hosts = try std.fs.Dir.createFileZ(util.cwd, try util.getenv(util.consts.ENV_KEY_TMP_HOSTS_PATH), .{ .truncate = true }); + var tmp_hosts = try std.fs.Dir.createFileZ(util.cwd, util.consts.TMP_HOSTS_FILE, .{ .truncate = true }); defer tmp_hosts.close(); try purge_existing(old_hosts, tmp_hosts); @@ -119,7 +119,7 @@ fn move_tmp_hosts() !void { var target_hosts = try std.fs.Dir.createFileZ(util.cwd, try util.getenv(util.consts.ENV_KEY_OLD_HOSTS_PATH), .{ .lock = .exclusive }); defer target_hosts.close(); const target_writer = target_hosts.writer(); - var tmp_hosts = try std.fs.Dir.openFileZ(util.cwd, try util.getenv(util.consts.ENV_KEY_TMP_HOSTS_PATH), .{}); + var tmp_hosts = try std.fs.Dir.openFileZ(util.cwd, util.consts.TMP_HOSTS_FILE, .{}); defer tmp_hosts.close(); const source_reader = tmp_hosts.reader(); @@ -129,5 +129,5 @@ fn move_tmp_hosts() !void { } }; - try std.fs.Dir.deleteFileZ(util.cwd, try util.getenv(util.consts.ENV_KEY_TMP_HOSTS_PATH)); + try std.fs.Dir.deleteFileZ(util.cwd, util.consts.TMP_HOSTS_FILE); }