core: initialize synced folder class only once [GH-3067]

This commit is contained in:
Mitchell Hashimoto 2014-03-06 08:35:21 -08:00
parent 46b5f0d22b
commit 79df69392f
2 changed files with 16 additions and 4 deletions

View File

@ -53,19 +53,26 @@ module Vagrant
end
end
# Build up the instances of the synced folders. We do this once
# so that they can store state.
folders = folders.map do |impl_name, fs|
instance = plugins[impl_name.to_sym][0].new
[instance, impl_name, fs]
end
# Go through each folder and prepare the folders
folders.each do |impl_name, fs|
folders.each do |impl, impl_name, fs|
@logger.info("Invoking synced folder prepare for: #{impl_name}")
plugins[impl_name.to_sym][0].new.prepare(env[:machine], fs, impl_opts(impl_name, env))
impl.prepare(env[:machine], fs, impl_opts(impl_name, env))
end
# Continue, we need the VM to be booted.
@app.call(env)
# Once booted, setup the folder contents
folders.each do |impl_name, fs|
folders.each do |impl, impl_name, fs|
@logger.info("Invoking synced folder enable: #{impl_name}")
plugins[impl_name.to_sym][0].new.enable(env[:machine], fs, impl_opts(impl_name, env))
impl.enable(env[:machine], fs, impl_opts(impl_name, env))
end
end
end

View File

@ -62,13 +62,16 @@ describe Vagrant::Action::Builtin::SyncedFolders do
end
it "should invoke prepare then enable" do
ids = []
order = []
tracker = Class.new(impl(true, "good")) do
define_method(:prepare) do |machine, folders, opts|
ids << self.object_id
order << :prepare
end
define_method(:enable) do |machine, folders, opts|
ids << self.object_id
order << :enable
end
end
@ -89,6 +92,8 @@ describe Vagrant::Action::Builtin::SyncedFolders do
subject.call(env)
order.should == [:prepare, :enable]
expect(ids.length).to eq(2)
expect(ids[0]).to eq(ids[1])
end
end
end