diff options
author | Claire McQuin <claire@getchef.com> | 2014-05-19 13:55:18 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-05-22 12:16:36 -0700 |
commit | 7d2891419ef04288ddd7bb2322df41cc9bd203dd (patch) | |
tree | 354eb64b83b99b4803fb8f7850483e9aca945f20 /lib/chef/config.rb | |
parent | 92519eb2cf7ae1b362f22d5710a229c5809a47cc (diff) | |
download | chef-7d2891419ef04288ddd7bb2322df41cc9bd203dd.tar.gz |
Put cache at HOME/.chef.d if /var/chef can't be accessed.
Diffstat (limited to 'lib/chef/config.rb')
-rw-r--r-- | lib/chef/config.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/chef/config.rb b/lib/chef/config.rb index 66dd4cc77e..fcab13ca5e 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -142,7 +142,7 @@ class Chef end end else - platform_specific_path("/var/chef") + cache_path end end @@ -240,10 +240,28 @@ class Chef if local_mode "#{config_dir}local-mode-cache" else - platform_specific_path("/var/chef") + primary_cache_root = platform_specific_path("/var") + primary_cache_path = platform_specific_path("/var/chef") + # Use /var/chef as the cache path only if that folder exists and we can read and write + # into it, or /var exists and we can read and write into it (we'll create /var/chef later). + # Otherwise, we'll create .chef.d under the user's home directory and use that as + # the cache path. + unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root) + secondary_cache_path = File.join(user_home, '.chef.d') + secondary_cache_path.gsub!(File::SEPARATOR, platform_path_separator) # Safety, mainly for Windows... + Chef::Log.warn("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}") + secondary_cache_path + else + primary_cache_path + end end end + # Returns true only if the path exists and is readable and writeable for the user. + def self.path_accessible?(path) + File.exists?(path) && File.readable?(path) && File.writable?(path) + end + # Where cookbook files are stored on the server (by content checksum) default(:checksum_path) { path_join(cache_path, "checksums") } |