Skip to content

Commit

Permalink
Nice error message given if ".vagrant" is a directory and therefore c…
Browse files Browse the repository at this point in the history
…an't be accessed. [closes hashicorpGH-172]
  • Loading branch information
mitchellh committed Oct 7, 2010
1 parent 9f5641f commit e36a9d3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant/data_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def initialize(file_path)
end
rescue Errno::ENOENT
clear
rescue Errno::EISDIR
raise Errors::DotfileIsDirectory
end

# Commits any changes to the data to disk. Even if the data
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class ConfigValidationFailed < VagrantError
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")
Expand Down
6 changes: 6 additions & 0 deletions templates/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion test/vagrant/data_store_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "fileutils"
require "test_helper"

class DataStoreTest < Test::Unit::TestCase
Expand All @@ -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
Expand Down

0 comments on commit e36a9d3

Please sign in to comment.