lib/invoker/power/setup.rb in invoker-1.0.2 vs lib/invoker/power/setup.rb in invoker-1.0.3
- old
+ new
@@ -2,10 +2,12 @@
module Invoker
module Power
class Setup
RESOLVER_FILE = "/etc/resolver/dev"
+ RESOLVER_DIR = "/etc/resolver"
+
FIREWALL_PLIST_FILE = "/Library/LaunchDaemons/com.codemancers.invoker.firewall.plist"
def self.install
installer = new
if Invoker.darwin?
if installer.check_if_setup_can_run?
@@ -73,11 +75,11 @@
def port_finder
@port_finder ||= Invoker::Power::PortFinder.new()
end
def install_resolver(dns_port)
- File.open(RESOLVER_FILE, "w") { |fl|
+ open_resolver_for_write { |fl|
fl.write(resolve_string(dns_port))
}
rescue Errno::EACCES
Invoker::Logger.puts("Running setup requires root access, please rerun it with sudo".color(:red))
raise
@@ -167,8 +169,18 @@
"If .dev domains still don't resolve locally. Try turning off the wi-fi"\
" and turning it on. It will force OSX to reload network configuration".color(:green)
end
replace_resolver_flag
end
+
+ private
+ def open_resolver_for_write
+ FileUtils.mkdir(RESOLVER_DIR) unless Dir.exists?(RESOLVER_DIR)
+ fl = File.open(RESOLVER_FILE, "w")
+ yield fl
+ ensure
+ fl && fl.close()
+ end
+
end
end
end