file download from http fix with correct options for windows
This commit is contained in:
parent
51853e2e8a
commit
bd69c54379
|
@ -48,12 +48,16 @@ module Vagrant
|
||||||
|
|
||||||
def with_tempfile
|
def with_tempfile
|
||||||
logger.info "Creating tempfile for storing box file..."
|
logger.info "Creating tempfile for storing box file..."
|
||||||
# create, write only, fail if the file exists
|
File.open(box_temp_path, file_options) do |tempfile|
|
||||||
File.open(box_temp_path, File::WRONLY|File::EXCL|File::CREAT) do |tempfile|
|
|
||||||
yield tempfile
|
yield tempfile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file_options
|
||||||
|
# create, write only, fail if the file exists, binary if windows
|
||||||
|
File::WRONLY|File::EXCL|File::CREAT|(Mario::Platform.windows? ? File::BINARY : 0)
|
||||||
|
end
|
||||||
|
|
||||||
def box_temp_path
|
def box_temp_path
|
||||||
File.join(@runner.env.tmp_path, BASENAME + Time.now.to_i.to_s)
|
File.join(@runner.env.tmp_path, BASENAME + Time.now.to_i.to_s)
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,6 +94,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
||||||
@action.with_tempfile
|
@action.with_tempfile
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
should "yield the tempfile object" do
|
should "yield the tempfile object" do
|
||||||
@tempfile = mock("tempfile")
|
@tempfile = mock("tempfile")
|
||||||
File.expects(:open).yields(@tempfile)
|
File.expects(:open).yields(@tempfile)
|
||||||
|
@ -104,6 +105,19 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "file options" do
|
||||||
|
should "include add binary bit to options on windows platform" do
|
||||||
|
Mario::Platform.expects(:windows?).returns(true)
|
||||||
|
assert_equal @action.file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not include binary bit on other platforms" do
|
||||||
|
Mario::Platform.expects(:windows?).returns(false)
|
||||||
|
assert_equal @action.file_options, File::CREAT|File::EXCL|File::WRONLY
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
context "cleaning up" do
|
context "cleaning up" do
|
||||||
setup do
|
setup do
|
||||||
@temp_path = "foo"
|
@temp_path = "foo"
|
||||||
|
|
Loading…
Reference in New Issue