Remove tmp hosts var, open a predefined one in the cwd
This commit is contained in:
parent
f8c4545ea6
commit
56ba739871
2 changed files with 4 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
pub const ENV_KEY_OLD_HOSTS_PATH = "OLD_HOSTS_PATH";
|
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_TARGET_DOMAIN = "TARGET_DOMAIN";
|
||||||
pub const ENV_KEY_SUBDOMAIN_LIST = "SUBDOMAIN_LIST";
|
pub const ENV_KEY_SUBDOMAIN_LIST = "SUBDOMAIN_LIST";
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ fn get_subdomains() !std.mem.SplitIterator(u8, .scalar) {
|
||||||
fn create_tmp_hosts(ip: util.IP, domain: util.Domain) !void {
|
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 });
|
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();
|
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();
|
defer tmp_hosts.close();
|
||||||
|
|
||||||
try purge_existing(old_hosts, tmp_hosts);
|
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 });
|
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();
|
defer target_hosts.close();
|
||||||
const target_writer = target_hosts.writer();
|
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();
|
defer tmp_hosts.close();
|
||||||
const source_reader = tmp_hosts.reader();
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue