switch to File.open for downloader temp file path to prevent minitar issues on windows

This commit is contained in:
John Bender 2010-03-21 23:50:08 -07:00
parent 35e9fa53d4
commit 0c00201a6b
5 changed files with 84 additions and 73 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ _site/*
*.org
.yardoc/
doc/
*~

View File

@ -51,11 +51,16 @@ module Vagrant
def with_tempfile
logger.info "Creating tempfile for storing box file..."
Tempfile.open(BASENAME, @runner.env.tmp_path) do |tempfile|
# create, write only, fail if the file exists
File.open(file_temp_path, File::WRONLY|File::EXCL|File::CREAT) do |tempfile|
yield tempfile
end
end
def file_temp_path
File.join(@runner.env.tmp_path, BASENAME + Time.now.to_i.to_s)
end
def download_to(f)
logger.info "Copying box to temporary location..."
downloader.download!(@runner.uri, f)

View File

@ -81,13 +81,15 @@ class DownloadBoxActionTest < Test::Unit::TestCase
context "tempfile" do
should "create a tempfile in the vagrant tmp directory" do
Tempfile.expects(:open).with(Vagrant::Actions::Box::Download::BASENAME, @runner.env.tmp_path).once
File.expects(:open).with { |name, bitmask|
name =~ /#{Vagrant::Actions::Box::Download::BASENAME}/ && name =~ /#{@runner.env.tmp_path}/
}.once
@action.with_tempfile
end
should "yield the tempfile object" do
@tempfile = mock("tempfile")
Tempfile.expects(:open).yields(@tempfile)
File.expects(:open).yields(@tempfile)
@action.with_tempfile do |otherfile|
assert @tempfile.equal?(otherfile)

View File

@ -159,6 +159,7 @@ class EnvironmentTest < Test::Unit::TestCase
should "default the path to the cwd instance var if nil" do
@path = mock("path")
@path.stubs(:root?).returns(true)
File.expects(:expand_path).with(@env.cwd).returns(@env.cwd)
Pathname.expects(:new).with(@env.cwd).returns(@path)
@env.load_root_path!(nil)
end
@ -181,7 +182,8 @@ class EnvironmentTest < Test::Unit::TestCase
search_seq = sequence("search_seq")
paths.each do |path|
File.expects(:exist?).with("#{path}/#{Vagrant::Environment::ROOTFILE_NAME}").returns(false).in_sequence(search_seq)
# NOTE File.expect(:expand_path) causes tests to hang in windows below is the interim solution
File.expects(:exist?).with("#{File.expand_path(path)}/#{Vagrant::Environment::ROOTFILE_NAME}").returns(false).in_sequence(search_seq)
end
assert !@env.load_root_path!(paths.first)
@ -203,7 +205,8 @@ class EnvironmentTest < Test::Unit::TestCase
end
should "should set the path for the rootfile" do
path = "/foo"
# NOTE File.expect(:expand_path) causes tests to hang in windows below is the interim solution
path = File.expand_path("/foo")
File.expects(:exist?).with("#{path}/#{Vagrant::Environment::ROOTFILE_NAME}").returns(true)
assert @env.load_root_path!(Pathname.new(path))