diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 67a735f52..db76f1884 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -642,6 +642,10 @@ module Vagrant version_file = @home_path.join("setup_version") if version_file.file? version = version_file.read + if version > CURRENT_SETUP_VERSION + raise Errors::HomeDirectoryLaterVersion + end + case version when CURRENT_SETUP_VERSION # We're already good, at the latest version. diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index fe563694b..5927c5bfd 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -260,6 +260,10 @@ module Vagrant error_key(:environment_locked) end + class HomeDirectoryLaterVersion < VagrantError + error_key(:home_dir_later_version) + end + class HomeDirectoryNotAccessible < VagrantError error_key(:home_dir_not_accessible) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 9f44e0da3..2739a8b3f 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -432,6 +432,11 @@ en: as mounting shared folders and configuring networks. Please add the ability to detect this guest operating system to Vagrant by creating a plugin or reporting a bug. + home_dir_later_version: |- + It appears that a newer version of Vagrant was run on this machine + at some point. The current version of Vagrant is unable to read + the configuration structure of this newer version. Please upgrade to + the latest version of Vagrant. home_dir_not_accessible: |- The home directory you specified is not accessible. The home directory that Vagrant uses must be both readable and writable. diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 7448d5170..e7499aa7a 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -69,6 +69,17 @@ describe Vagrant::Environment do end end + it "raises an exception if the version is newer than ours" do + Dir.mktmpdir do |dir| + Pathname.new(dir).join("setup_version").open("w") do |f| + f.write("100.5") + end + + expect { described_class.new(home_path: dir) }. + to raise_error(Vagrant::Errors::HomeDirectoryLaterVersion) + end + end + it "raises an exception if there is an unknown home directory version" do Dir.mktmpdir do |dir| Pathname.new(dir).join("setup_version").open("w") do |f| @@ -105,37 +116,6 @@ describe Vagrant::Environment do collection.should_receive(:upgrade_v1_1_v1_5).once subject end -=begin - # Create all the old box directories - boxdir = env.homedir.join("boxes") - boxdir.mkpath - - foo_path = boxdir.join("foo", "virtualbox") - vbox_path = boxdir.join("precise64", "virtualbox") - vmware_path = boxdir.join("precise64", "vmware") - v1_path = boxdir.join("v1box") - - [foo_path, vbox_path, vmware_path].each do |path| - path.mkpath - path.join("name").open("w") do |f| - f.write(path.to_s) - end - end - - v1_path.mkpath - v1_path.join("name").open("w") { |f| f.write("v1box") } - - # Upgrade! - subject - - expect(boxdir).to be_directory - expect(boxdir.children(false).map(&:to_s).sort).to eq( - ["foo", "precise64", "v1box"]) - expect(foo_path).to_not exist - expect(vbox_path).to_not exist - expect(vmware_path).to_not exist - expect(v1_path).to_not exist -=end end end