From 2e3e01ccc851897b6e8552c15e118e82a9abb0f8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 25 May 2026 21:10:58 +0300 Subject: fix(wireguard): remove memoization from config_contents and hosts_contents Stale external changes to wg1.conf or /etc/hosts were invisible because LocalWireGuard cached the first read forever. Remove the cache entirely so every operation sees the current file state. Also removed the now-unnecessary ivar updates after write_config/write_hosts. --- lib/hyperstack/wireguard.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'lib/hyperstack') diff --git a/lib/hyperstack/wireguard.rb b/lib/hyperstack/wireguard.rb index 46bd682..bb845e9 100644 --- a/lib/hyperstack/wireguard.rb +++ b/lib/hyperstack/wireguard.rb @@ -36,7 +36,6 @@ module HyperstackVM write_config(updated) restart_service_if_active - @config_contents = updated removed end @@ -52,7 +51,6 @@ module HyperstackVM return removed if dry_run write_hosts(updated) - @hosts_contents = updated removed end @@ -177,21 +175,17 @@ module HyperstackVM end def config_contents - return @config_contents if defined?(@config_contents) - - @config_contents = File.read(@config_path) + File.read(@config_path) rescue Errno::EACCES, Errno::ENOENT stdout, _stderr, status = Open3.capture3('sudo', '-n', 'cat', @config_path) - @config_contents = status.success? ? stdout : nil + status.success? ? stdout : nil end def hosts_contents - return @hosts_contents if defined?(@hosts_contents) - - @hosts_contents = File.read('/etc/hosts') + File.read('/etc/hosts') rescue Errno::EACCES, Errno::ENOENT stdout, _stderr, status = Open3.capture3('sudo', '-n', 'cat', '/etc/hosts') - @hosts_contents = status.success? ? stdout : nil + status.success? ? stdout : nil end def prune_hosts_entries(content, hostnames) -- cgit v1.2.3