From f022e9ee36e00139231eb9c2186b659aebe36467 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Jan 2012 21:06:09 -0800 Subject: [PATCH] Fix issue where chef solo always expected "cookbooks" folder [GH-638] --- CHANGELOG.md | 2 ++ lib/vagrant/provisioners/chef.rb | 2 +- lib/vagrant/provisioners/chef_solo.rb | 36 +++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 620286630..4d44d96dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.9.2 (unreleased) - Support shell expansions in shared folder guest paths again. [GH-656] + - Fix issue where Chef solo always expected the host to have a + "cookbooks" folder in their directory. [GH-638] - Fix `forward_agent` not working when outside of blocks. [GH-651] - Fix issue causing custom guest implementations to not load properly. - Filter clear screen character out of output on SSH. diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 6824a4faa..b51e0e868 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -150,7 +150,7 @@ module Vagrant def validate(env, errors) super - errors.add(I18n.t("vagrant.config.chef.vagrant_as_json_key")) if @json.has_key?(:vagrant) + errors.add(I18n.t("vagrant.config.chef.vagrant_as_json_key")) if json.has_key?(:vagrant) end def instance_variables_hash diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index ec8be6edf..06d67d622 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -16,10 +16,23 @@ module Vagrant attr_accessor :recipe_url attr_accessor :nfs + def initialize + super + + @__default = ["cookbooks", [:vm, "cookbooks"]] + end + # Provide defaults in such a way that they won't override the instance # variable. This is so merging continues to work properly. def cookbooks_path - @cookbooks_path || ["cookbooks", [:vm, "cookbooks"]] + @cookbooks_path || _default_cookbook_path + end + + # This stores a reference to the default cookbook path which is used + # later. Do not use this publicly. I apologize for not making it + # "protected" but it has to be called by Vagrant internals later. + def _default_cookbook_path + @__default end def nfs @@ -86,16 +99,27 @@ module Vagrant # path element which contains the folder location (:host or :vm) paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol) - paths.map do |path| + results = [] + paths.each do |path| path = [:host, path] if !path.is_a?(Array) type, path = path # Create the local/remote path based on whether this is a host # or VM path. local_path = nil - local_path = File.expand_path(path, env[:root_path]) if type == :host remote_path = nil if type == :host + # Get the expanded path that the host path points to + local_path = File.expand_path(path, env[:root_path]) + + # Super hacky but if we're expanded the default cookbook paths, + # and one of the host paths doesn't exist, then just ignore it, + # because that is fine. + if paths.equal?(config._default_cookbook_path) && !File.directory?(local_path) + @logger.info("'cookbooks' folder doesn't exist on defaults. Ignoring.") + next + end + # Path exists on the host, setup the remote path remote_path = "#{config.provisioning_path}/chef-solo-#{get_and_update_counter(:cookbooks_path)}" else @@ -113,9 +137,11 @@ module Vagrant # If we have specified a folder name to append then append it remote_path += "/#{appended_folder}" if appended_folder - # Return the result - [type, local_path, remote_path] + # Append the result + results << [type, local_path, remote_path] end + + results end # Shares the given folders with the given prefix. The folders should