From e7bed7c2fff48c53d224e6e198139c50b08c1699 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 1 Jul 2012 21:52:18 -0700 Subject: [PATCH] Raise an exception if an invalid tar file is added. --- lib/vagrant/box_collection2.rb | 7 ++++++- test/unit/vagrant/box_collection2_test.rb | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/box_collection2.rb b/lib/vagrant/box_collection2.rb index 830aa7e90..04c837cdd 100644 --- a/lib/vagrant/box_collection2.rb +++ b/lib/vagrant/box_collection2.rb @@ -26,6 +26,7 @@ module Vagrant # * BoxAlreadyExists - The box you're attempting to add already exists. # * BoxProviderDoesntMatch - If the given box provider doesn't match the # actual box provider in the untarred box. + # * BoxUnpackageFailure - An invalid tar file. # * BoxUpgradeRequired - You're attempting to add a box when there is a # V1 box with the same name that must first be upgraded. # @@ -53,7 +54,11 @@ module Vagrant # Change directory to the box directory and unpackage the tar Dir.chdir(box_dir) do @logger.debug("Unpacking box file into box directory...") - Archive::Tar::Minitar.unpack(path.to_s, box_dir.to_s) + begin + Archive::Tar::Minitar.unpack(path.to_s, box_dir.to_s) + rescue SystemCallError + raise Errors::BoxUnpackageFailure + end end # Find the box we just added diff --git a/test/unit/vagrant/box_collection2_test.rb b/test/unit/vagrant/box_collection2_test.rb index b99bd765c..ee95e3694 100644 --- a/test/unit/vagrant/box_collection2_test.rb +++ b/test/unit/vagrant/box_collection2_test.rb @@ -65,6 +65,10 @@ describe Vagrant::BoxCollection2 do # Verify the box doesn't exist instance.find(box_name, bad_provider).should be_nil end + + it "should raise an exception if you add an invalid box file" do + pending "I don't know how to generate an invalid tar." + end end describe "listing all" do