From e36a9d3a0cf4e888964b08945354879c699fb330 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 6 Oct 2010 18:57:39 -0700 Subject: [PATCH] Nice error message given if ".vagrant" is a directory and therefore can't be accessed. [closes GH-172] --- CHANGELOG.md | 2 ++ lib/vagrant/data_store.rb | 2 ++ lib/vagrant/errors.rb | 5 +++++ templates/locales/en.yml | 6 ++++++ test/vagrant/data_store_test.rb | 11 ++++++++++- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53dc978a7..17498eb43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.6.5 (unreleased) + - A nice error message is given if ".vagrant" is a directory and therefore + can't be accessed. [GH-172] - Fix plugin loading in a Rails 2.3.x project. [GH-176] ## 0.6.4 (October 4, 2010) diff --git a/lib/vagrant/data_store.rb b/lib/vagrant/data_store.rb index 60a4317dc..ca85ddb6f 100644 --- a/lib/vagrant/data_store.rb +++ b/lib/vagrant/data_store.rb @@ -24,6 +24,8 @@ module Vagrant end rescue Errno::ENOENT clear + rescue Errno::EISDIR + raise Errors::DotfileIsDirectory end # Commits any changes to the data to disk. Even if the data diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index a123da3df..54d6a8c09 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -133,6 +133,11 @@ module Vagrant error_key(:config_validation) end + class DotfileIsDirectory < VagrantError + status_code(46) + error_key(:dotfile_is_directory) + end + class DownloaderFileDoesntExist < VagrantError status_code(37) error_key(:file_missing, "vagrant.downloaders.file") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e38f2331d..c0dbb4607 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -15,6 +15,12 @@ en: are printed below: %{messages} + dotfile_is_directory: |- + The local file Vagrant uses to store data ".vagrant" already exists + and is a directory! If you are in your home directory, then please run + this command in another directory. If you aren't in a home directory, + then please rename ".vagrant" to something else, or configure Vagrant + to use another filename by modifying `config.vagrant.dotfile_name`. interrupted: Vagrant exited after cleanup due to external interrupt. multi_vm_required: A multi-vm environment is required for name specification to this command. multi_vm_target_required: `vagrant %{command}` requires a specific VM name to target in a multi-VM environment. diff --git a/test/vagrant/data_store_test.rb b/test/vagrant/data_store_test.rb index 61f117495..51c06b82b 100644 --- a/test/vagrant/data_store_test.rb +++ b/test/vagrant/data_store_test.rb @@ -1,3 +1,4 @@ +require "fileutils" require "test_helper" class DataStoreTest < Test::Unit::TestCase @@ -11,7 +12,15 @@ class DataStoreTest < Test::Unit::TestCase end teardown do - File.delete(@db_file) if File.file?(@db_file) + File.delete(@db_file) if File.exist?(@db_file) + end + + should "raise an exception if the db file is a directory" do + file = tmp_path.join("data_store_folder_test") + FileUtils.mkdir_p(file) + assert_raises (Vagrant::Errors::DotfileIsDirectory) { + @klass.new(file) + } end should "be a hash with indifferent access" do