file download from http fix with correct options for windows
This commit is contained in:
parent
51853e2e8a
commit
bd69c54379
|
@ -48,11 +48,15 @@ module Vagrant
|
|||
|
||||
def with_tempfile
|
||||
logger.info "Creating tempfile for storing box file..."
|
||||
# create, write only, fail if the file exists
|
||||
File.open(box_temp_path, File::WRONLY|File::EXCL|File::CREAT) do |tempfile|
|
||||
File.open(box_temp_path, file_options) do |tempfile|
|
||||
yield tempfile
|
||||
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
|
||||
File.join(@runner.env.tmp_path, BASENAME + Time.now.to_i.to_s)
|
||||
|
|
|
@ -94,6 +94,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
|||
@action.with_tempfile
|
||||
end
|
||||
|
||||
|
||||
should "yield the tempfile object" do
|
||||
@tempfile = mock("tempfile")
|
||||
File.expects(:open).yields(@tempfile)
|
||||
|
@ -104,6 +105,19 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
|||
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
|
||||
setup do
|
||||
@temp_path = "foo"
|
||||
|
|
Loading…
Reference in New Issue