summaryrefslogtreecommitdiff
path: root/lib/chef/config.rb
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2014-05-29 16:50:19 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2014-05-29 16:50:19 -0700
commita6b19c08da6365e883d38d0ed202068df16301ab (patch)
treef062813b74e892fe5e4359ded2c9c2618b546a94 /lib/chef/config.rb
parent901479d9e4d42f186ede7baf5fa964c4dfa8eb26 (diff)
parent0e8208ff64e228cbf2b2dda679756b3e83cf9823 (diff)
downloadchef-a6b19c08da6365e883d38d0ed202068df16301ab.tar.gz
Merge pull request #1442 from opscode/CHEF-5259
Put cache at HOME/.chef if /var/chef can't be accessed.
Diffstat (limited to 'lib/chef/config.rb')
-rw-r--r--lib/chef/config.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index d884aabc3d..65ef1ac576 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 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')
+ secondary_cache_path.gsub!(File::SEPARATOR, platform_path_separator) # Safety, mainly for Windows...
+ Chef::Log.info("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") }