diff options
author | Kartik Null Cating-Subramanian <ksubramanian@chef.io> | 2015-03-17 18:47:08 -0400 |
---|---|---|
committer | Kartik Null Cating-Subramanian <ksubramanian@chef.io> | 2015-03-20 11:22:30 -0400 |
commit | 8adb5e38a31f47d84fcac6c825b5bd9279ba6aac (patch) | |
tree | 55052f72db7172064e5bb8b77869598a0ebc9b03 | |
parent | 55d9ee24a8b2b14af415a36ff3c60b737dd84027 (diff) | |
download | chef-8adb5e38a31f47d84fcac6c825b5bd9279ba6aac.tar.gz |
Modify accesses to HOME to use path_helper instead.
-rw-r--r-- | lib/chef/config.rb | 6 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 3 | ||||
-rw-r--r-- | lib/chef/knife/core/subcommand_loader.rb | 8 | ||||
-rw-r--r-- | lib/chef/knife/exec.rb | 3 | ||||
-rw-r--r-- | lib/chef/knife/ssh.rb | 7 | ||||
-rw-r--r-- | lib/chef/provider/service/macosx.rb | 3 | ||||
-rw-r--r-- | lib/chef/shell.rb | 12 | ||||
-rw-r--r-- | lib/chef/workstation_config_loader.rb | 7 |
8 files changed, 27 insertions, 22 deletions
diff --git a/lib/chef/config.rb b/lib/chef/config.rb index 4595e9e33e..058e74e83d 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -570,12 +570,8 @@ class Chef ENV end - def self.windows_home_path - env['SYSTEMDRIVE'] + env['HOMEPATH'] if env['SYSTEMDRIVE'] && env['HOMEPATH'] - end - # returns a platform specific path to the user home dir if set, otherwise default to current directory. - default( :user_home ) { env['HOME'] || windows_home_path || env['USERPROFILE'] || Dir.pwd } + default( :user_home ) { PathHelper.home || Dir.pwd } # Enable file permission fixup for selinux. Fixup will be done # only if selinux is enabled in the system. diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index e168a6bd9b..64d1d0c378 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -21,6 +21,7 @@ require 'chef/knife/data_bag_secret_options' require 'erubis' require 'chef/knife/bootstrap/chef_vault_handler' require 'chef/knife/bootstrap/client_builder' +require 'chef/util/path_helper' class Chef class Knife @@ -268,7 +269,7 @@ class Chef bootstrap_files = [] bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap/templates', "#{template}.erb") bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{template}.erb") if Chef::Knife.chef_config_dir - bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{template}.erb") if ENV['HOME'] + Chef::Util::PathHelper.home('.chef', 'bootstrap', "#{template}.erb") {|p| bootstrap_files << p} bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{template}.erb")) bootstrap_files.flatten! diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index f9b8f5008e..915042175e 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -49,7 +49,9 @@ class Chef end # finally search ~/.chef/plugins/knife/*.rb - user_specific_files.concat Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(env['HOME'], '.chef', 'plugins', 'knife'), '*.rb')) if env['HOME'] + Chef::Util::PathHelper.home('.chef', 'plugins', 'knife') do |p| + user_specific_files.concat Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(p), '*.rb')) + end user_specific_files end @@ -140,7 +142,7 @@ class Chef end def have_plugin_manifest? - ENV["HOME"] && File.exist?(plugin_manifest_path) + plugin_manifest_path && File.exist?(plugin_manifest_path) end def plugin_manifest @@ -148,7 +150,7 @@ class Chef end def plugin_manifest_path - File.join(ENV['HOME'], '.chef', 'plugin_manifest.json') + Chef::Util::PathHelper.home('.chef', 'plugin_manifest.json') end private diff --git a/lib/chef/knife/exec.rb b/lib/chef/knife/exec.rb index 3e8196c616..ace4ee2300 100644 --- a/lib/chef/knife/exec.rb +++ b/lib/chef/knife/exec.rb @@ -17,6 +17,7 @@ # require 'chef/knife' +require 'chef/util/path_helper' class Chef::Knife::Exec < Chef::Knife @@ -42,7 +43,7 @@ class Chef::Knife::Exec < Chef::Knife # Default script paths are chef-repo/.chef/scripts and ~/.chef/scripts config[:script_path] << File.join(Chef::Knife.chef_config_dir, 'scripts') if Chef::Knife.chef_config_dir - config[:script_path] << File.join(ENV['HOME'], '.chef', 'scripts') if ENV['HOME'] + Chef::Util::PathHelper.home('.chef', 'scripts') { |p| config[:script_path] << p } scripts = Array(name_args) context = Object.new diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index db0fb7dd41..50fedd0e49 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -31,6 +31,7 @@ class Chef require 'chef/search/query' require 'chef/mixin/shell_out' require 'chef/mixin/command' + require 'chef/util/path_helper' require 'mixlib/shellout' end @@ -342,8 +343,10 @@ class Chef def screen tf = Tempfile.new("knife-ssh-screen") - if File.exist? "#{ENV["HOME"]}/.screenrc" - tf.puts("source #{ENV["HOME"]}/.screenrc") + Chef::Util::PathHelper.home('.screenrc') do |screenrc_path| + if File.exist? screenrc_path + tf.puts("source #{screenrc_path}") + end end tf.puts("caption always '%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<'") tf.puts("hardstatus alwayslastline 'knife ssh #{@name_args[0]}'") diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index 10ad1aa29d..df5be54fda 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -33,8 +33,7 @@ class Chef /Library/LaunchDaemons /System/Library/LaunchAgents /System/Library/LaunchDaemons } - - locations << "#{ENV['HOME']}/Library/LaunchAgents" if ENV['HOME'] + Chef::Util::PathHelper.home('Library', 'LaunchAgents') { |p| locations << p } locations end diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb index fed32b3795..ee4fe78808 100644 --- a/lib/chef/shell.rb +++ b/lib/chef/shell.rb @@ -29,6 +29,7 @@ require 'chef/config_fetcher' require 'chef/shell/shell_session' require 'chef/shell/ext' require 'chef/json_compat' +require 'chef/util/path_helper' # = Shell # Shell is Chef in an IRB session. Shell can interact with a Chef server via the @@ -101,7 +102,7 @@ module Shell end def self.configure_irb - irb_conf[:HISTORY_FILE] = "~/.chef/chef_shell_history" + irb_conf[:HISTORY_FILE] = Chef::Util::PathHelper.home(".chef", "chef_shell_history") irb_conf[:SAVE_HISTORY] = 1000 irb_conf[:IRB_RC] = lambda do |conf| @@ -295,18 +296,19 @@ FOOTER private def config_file_for_shell_mode(environment) + dot_chef_dir = Chef::Util::PathHelper.home('.chef') if config[:config_file] config[:config_file] - elsif environment && ENV['HOME'] + elsif environment Shell.env = environment - config_file_to_try = ::File.join(ENV['HOME'], '.chef', environment, 'chef_shell.rb') + config_file_to_try = ::File.join(dot_chef_dir, environment, 'chef_shell.rb') unless ::File.exist?(config_file_to_try) puts "could not find chef-shell config for environment #{environment} at #{config_file_to_try}" exit 1 end config_file_to_try - elsif ENV['HOME'] && ::File.exist?(File.join(ENV['HOME'], '.chef', 'chef_shell.rb')) - File.join(ENV['HOME'], '.chef', 'chef_shell.rb') + elsif dot_chef_dir && ::File.exist?(File.join(dot_chef_dir, 'chef_shell.rb')) + File.join(dot_chef_dir, 'chef_shell.rb') elsif config[:solo] Chef::Config.platform_specific_path("/etc/chef/solo.rb") elsif config[:client] diff --git a/lib/chef/workstation_config_loader.rb b/lib/chef/workstation_config_loader.rb index dd02ad9a66..2454c9cccf 100644 --- a/lib/chef/workstation_config_loader.rb +++ b/lib/chef/workstation_config_loader.rb @@ -19,6 +19,7 @@ require 'chef/config_fetcher' require 'chef/config' require 'chef/null_logger' +require 'chef/util/path_helper' class Chef @@ -112,9 +113,9 @@ class Chef candidate_configs << File.join(chef_config_dir, 'knife.rb') end # Look for $HOME/.chef/knife.rb - if env['HOME'] - candidate_configs << File.join(env['HOME'], '.chef', 'config.rb') - candidate_configs << File.join(env['HOME'], '.chef', 'knife.rb') + Chef::Util::PathHelper.home('.chef') do |dot_chef_dir| + candidate_configs << File.join(dot_chef_dir, 'config.rb') + candidate_configs << File.join(dot_chef_dir, 'knife.rb') end candidate_configs.find do | candidate_config | |