lib/invoker.rb in invoker-1.2.0.pre1 vs lib/invoker.rb in invoker-1.2.0.pre2
- old
+ new
@@ -6,10 +6,11 @@
require "ostruct"
require "uuid"
require "json"
require "rainbow"
require "rainbow/ext/string"
+require "etc"
require "invoker/version"
require "invoker/logger"
require "invoker/daemon"
require "invoker/cli"
@@ -62,31 +63,31 @@
def daemon
@daemon ||= Invoker::Daemon.new
end
def can_run_balancer?(throw_warning = true)
- return true if File.exist?(Invoker::Power::Config::CONFIG_LOCATION)
+ return true if File.exist?(Invoker::Power::Config.config_file)
if throw_warning
Invoker::Logger.puts("Invoker has detected setup has not been run. Domain feature will not work without running setup command.".color(:red))
end
false
end
def setup_config_location
- config_location = File.join(Dir.home, '.invoker')
- return config_location if Dir.exist?(config_location)
+ config_dir = Invoker::Power::Config.config_dir
+ return config_dir if Dir.exist?(config_dir)
- if File.exist?(config_location)
- old_config = File.read(config_location)
- FileUtils.rm_f(config_location)
+ if File.exist?(config_dir)
+ old_config = File.read(config_dir)
+ FileUtils.rm_f(config_dir)
end
- FileUtils.mkdir(config_location)
+ FileUtils.mkdir(config_dir)
- migrate_old_config(old_config, config_location) if old_config
- config_location
+ migrate_old_config(old_config, config_dir) if old_config
+ config_dir
end
def run_without_bundler
if defined?(Bundler)
Bundler.with_clean_env do
@@ -112,9 +113,22 @@
def migrate_old_config(old_config, config_location)
new_config = File.join(config_location, 'config')
File.open(new_config, 'w') do |file|
file.write(old_config)
+ end
+ end
+
+ # On some platforms `Dir.home` or `ENV['HOME']` does not return home directory of user.
+ # this is especially true, after effective and real user id of process
+ # has been changed.
+ #
+ # @return [String] home directory of the user
+ def home
+ if File.writable?(Dir.home)
+ Dir.home
+ else
+ Etc.getpwuid(Process.uid).dir
end
end
end
end