From e5539eb769452ac9b0168edf56cb43a2447a7356 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 30 Mar 2013 14:57:42 -0700 Subject: [PATCH] Only prepend/append once for hooks --- lib/vagrant/action/builder.rb | 15 ++++++++++++++- test/unit/vagrant/action/builder_test.rb | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/builder.rb b/lib/vagrant/action/builder.rb index 5e21adb5c..95fa96267 100644 --- a/lib/vagrant/action/builder.rb +++ b/lib/vagrant/action/builder.rb @@ -133,9 +133,22 @@ module Vagrant if env[:action_hooks] builder = self.dup + # These are the options to pass into hook application. + options = {} + + # If we already ran through once and did append/prepends, + # then don't do it again. + if env[:action_hooks_already_ran] + options[:no_prepend_or_append] = true + end + + # Specify that we already ran, so in the future we don't repeat + # the prepend/append hooks. + env[:action_hooks_already_ran] = true + # Apply all the hooks to the new builder instance env[:action_hooks].each do |hook| - hook.apply(builder) + hook.apply(builder, options) end # The stack is now the result of the new builder diff --git a/test/unit/vagrant/action/builder_test.rb b/test/unit/vagrant/action/builder_test.rb index a4fed47d5..474dc5642 100644 --- a/test/unit/vagrant/action/builder_test.rb +++ b/test/unit/vagrant/action/builder_test.rb @@ -191,6 +191,16 @@ describe Vagrant::Action::Builder do subject.call(data) data[:data].should == [1, 2] + data[:action_hooks_already_ran].should == true + end + + it "applies without prepend/append if it has already" do + hook = double("hook") + hook.should_receive(:apply).with(anything, { :no_prepend_or_append => true }).once + + data[:action_hooks] = [hook] + data[:action_hooks_already_ran] = true + subject.call(data) end end end