From 3e54150f71638046278028136e6c1db4c2741a4e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 1 Oct 2010 09:24:58 -0700 Subject: [PATCH] Box add checks if box exists before the download [closes GH-170] --- CHANGELOG.md | 1 + lib/vagrant/box.rb | 1 + test/vagrant/box_test.rb | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24864f14c..6eb6ad7f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.6.4 (unreleased) + - Box add checks if a box already exists before the download. [GH-170] - NFS no longer attempts to clean exports file if VM is not created, which was causing a stack trace during recovery. [related to GH-166] - Basic validation added for Chef configuration (both solo and server). diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index af5d7591a..1f4b17fdd 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -57,6 +57,7 @@ module Vagrant # method requires that `name` and `uri` be set. The logic of this method # is kicked out to the `box_add` registered middleware. def add + raise Errors::BoxAlreadyExists.new(:name => name) if File.directory?(directory) env.actions.run(:box_add, { "box" => self }) end diff --git a/test/vagrant/box_test.rb b/test/vagrant/box_test.rb index 64704c11e..5db224f9e 100644 --- a/test/vagrant/box_test.rb +++ b/test/vagrant/box_test.rb @@ -27,6 +27,14 @@ class BoxTest < Test::Unit::TestCase @box = Vagrant::Box.new(vagrant_env, "foo") end + should "raise an exception if a box exists with the name we're attempting to add" do + vagrant_box(@box.name) + + assert_raises(Vagrant::Errors::BoxAlreadyExists) { + @box.add + } + end + should "execute the Add action when add is called" do @box.env.actions.expects(:run).with(:box_add, { "box" => @box }) @box.add