From ab70dc271bc4188898b9cd4ad29156e705514678 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 23 Nov 2013 10:47:06 -0800 Subject: [PATCH] core: verify explicit sf types are usable --- lib/vagrant/action/builtin/synced_folders.rb | 17 +++++++++++++---- lib/vagrant/errors.rb | 4 ++++ templates/locales/en.yml | 4 ++++ .../action/builtin/synced_folders_test.rb | 8 ++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/action/builtin/synced_folders.rb b/lib/vagrant/action/builtin/synced_folders.rb index 4daba7a28..0d0eb9356 100644 --- a/lib/vagrant/action/builtin/synced_folders.rb +++ b/lib/vagrant/action/builtin/synced_folders.rb @@ -124,10 +124,19 @@ module Vagrant impl = "" impl = data[:type].to_sym if data[:type] - if impl != "" && !plugins[impl] - # This should never happen because configuration validation - # should catch this case. But we put this here as an assert - raise "Internal error. Report this as a bug. Invalid: #{data[:type]}" + if impl != "" + impl_class = plugins[impl] + if !impl_class + # This should never happen because configuration validation + # should catch this case. But we put this here as an assert + raise "Internal error. Report this as a bug. Invalid: #{data[:type]}" + end + + if !impl_class[0].new.usable?(machine) + # Verify that explicitly defined shared folder types are + # actually usable. + raise Errors::SyncedFolderUnusable, type: data[:type].to_s + end end # Keep track of this shared folder by the implementation. diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 625637883..6a8cd7466 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -512,6 +512,10 @@ module Vagrant error_key(:ssh_unavailable_windows) end + class SyncedFolderUnusable < VagrantError + error_key(:synced_folder_unusable) + end + class UIExpectsTTY < VagrantError error_key(:ui_expects_tty) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 5999ec4ba..114f53913 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -580,6 +580,10 @@ en: Port: %{port} Username: %{username} Private key: %{key_path} + synced_folder_unusable: |= + The synced folder type '%{type}' is reporting as unusable for + your current setup. Please verify you have all the proper + prerequisites for using this shared folder type and try again. test_key: "test value" ui_expects_tty: |- Vagrant is attempting to interface with the UI in a way that requires diff --git a/test/unit/vagrant/action/builtin/synced_folders_test.rb b/test/unit/vagrant/action/builtin/synced_folders_test.rb index ae7faddfc..2cb123096 100644 --- a/test/unit/vagrant/action/builtin/synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/synced_folders_test.rb @@ -160,6 +160,14 @@ describe Vagrant::Action::Builtin::SyncedFolders do result[:nfs].should == { "nfs" => folders["nfs"] } end + it "should error if an explicit type is unusable" do + plugins[:unusable] = [impl(false, "bad"), 15] + folders["root"] = { type: "unusable" } + + expect { subject.synced_folders(machine) }. + to raise_error + end + it "should ignore disabled folders" do folders["root"] = {} folders["foo"] = { disabled: true }