diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index 74def17a7..aca214028 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -26,6 +26,20 @@ module Vagrant return nil end + # This finds the options in the env that are set for a given + # synced folder type. + def impl_opts(name, env) + {}.tap do |result| + env.each do |k, v| + if k.to_s.start_with?("#{name}_") + k = k.dup if !k.is_a?(Symbol) + v = v.dup if !v.is_a?(Symbol) + result[k] = v + end + end + end + end + # This returns the available synced folder implementations. This # is a separate method so that it can be easily stubbed by tests. def plugins diff --git a/lib/vagrant/action/builtin/synced_folder_cleanup.rb b/lib/vagrant/action/builtin/synced_folder_cleanup.rb index 2670d9e11..ff2f65439 100644 --- a/lib/vagrant/action/builtin/synced_folder_cleanup.rb +++ b/lib/vagrant/action/builtin/synced_folder_cleanup.rb @@ -21,7 +21,8 @@ module Vagrant # Go through each folder and do cleanup folders.each_key do |impl_name| @logger.info("Invoking synced folder cleanup for: #{impl_name}") - plugins[impl_name.to_sym][0].new.cleanup(env[:machine]) + plugins[impl_name.to_sym][0].new.cleanup( + env[:machine], impl_opts(impl_name, env)) end @app.call(env) diff --git a/lib/vagrant/action/builtin/synced_folders.rb b/lib/vagrant/action/builtin/synced_folders.rb index a241c289a..7c7802ca2 100644 --- a/lib/vagrant/action/builtin/synced_folders.rb +++ b/lib/vagrant/action/builtin/synced_folders.rb @@ -73,20 +73,6 @@ module Vagrant plugins[impl_name.to_sym][0].new.enable(env[:machine], fs, impl_opts(impl_name, env)) end end - - # This finds the options in the env that are set for a given - # synced folder type. - def impl_opts(name, env) - {}.tap do |result| - env.each do |k, v| - if k.to_s.start_with?("#{name}_") - k = k.dup if !k.is_a?(Symbol) - v = v.dup if !v.is_a?(Symbol) - result[k] = v - end - end - end - end end end end diff --git a/lib/vagrant/plugin/v2/synced_folder.rb b/lib/vagrant/plugin/v2/synced_folder.rb index 1973bdb73..7904d47d3 100644 --- a/lib/vagrant/plugin/v2/synced_folder.rb +++ b/lib/vagrant/plugin/v2/synced_folder.rb @@ -27,10 +27,14 @@ module Vagrant end # This is called after destroying the machine during a - # `vagrant destroy`. + # `vagrant destroy` and also prior to syncing folders during + # a `vagrant up`. # # No return value. - def cleanup(machine) + # + # @param [Machine] machine + # @param [Hash] opts + def cleanup(machine, opts) end end end diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 3013b0d49..419b70a54 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -61,7 +61,7 @@ module VagrantPlugins end end - def cleanup(machine) + def cleanup(machine, opts) driver(machine).clear_shared_folders if machine.id && machine.id != "" end diff --git a/plugins/synced_folders/nfs/synced_folder.rb b/plugins/synced_folders/nfs/synced_folder.rb index fc618245f..be969d50c 100644 --- a/plugins/synced_folders/nfs/synced_folder.rb +++ b/plugins/synced_folders/nfs/synced_folder.rb @@ -51,7 +51,7 @@ module VagrantPlugins :mount_nfs_folder, nfsopts[:nfs_host_ip], mount_folders) end - def cleanup(machine) + def cleanup(machine, opts) # Get the ID of all active machines. ids = machine.env.active_machines.map do |name, provider| machine.env.machine(name, provider).id diff --git a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb index 2c766e200..97b64b168 100644 --- a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb @@ -38,6 +38,21 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do end end + describe "impl_opts" do + it "should return only relevant keys" do + env = { + :foo_bar => "baz", + :bar_bar => "nope", + :foo_baz => "bar", + } + + result = subject.impl_opts("foo", env) + result.length.should == 2 + result[:foo_bar].should == "baz" + result[:foo_baz].should == "bar" + end + end + describe "synced_folders" do let(:folders) { {} } let(:plugins) { {} } diff --git a/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb b/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb index 6375d25bb..310311967 100644 --- a/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb +++ b/test/unit/vagrant/action/builtin/synced_folder_cleanup_test.rb @@ -38,7 +38,7 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do class_variable_get(:@@clean) end - def cleanup(machine) + def cleanup(machine, opts) self.class.class_variable_set(:@@clean, true) end end @@ -75,7 +75,10 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do } expect_any_instance_of(tracker).to receive(:cleanup). - with(env[:machine]) + with(env[:machine], { tracker_foo: :bar }) + + # Test that the impl-specific opts are passed through + env[:tracker_foo] = :bar subject.call(env) end diff --git a/test/unit/vagrant/action/builtin/synced_folders_test.rb b/test/unit/vagrant/action/builtin/synced_folders_test.rb index d18ac15e2..e09ae181b 100644 --- a/test/unit/vagrant/action/builtin/synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/synced_folders_test.rb @@ -113,19 +113,4 @@ describe Vagrant::Action::Builtin::SyncedFolders do actual["root"][:foo].should == "bar" end end - - describe "impl_opts" do - it "should return only relevant keys" do - env = { - :foo_bar => "baz", - :bar_bar => "nope", - :foo_baz => "bar", - } - - result = subject.impl_opts("foo", env) - result.length.should == 2 - result[:foo_bar].should == "baz" - result[:foo_baz].should == "bar" - end - end end