file copy fix
This commit is contained in:
parent
a71815df4e
commit
751a8bfa1b
|
@ -3,19 +3,9 @@ module Vagrant
|
|||
# "Downloads" a file to a temporary file. Basically, this downloader
|
||||
# simply does a file copy.
|
||||
class File < Base
|
||||
BUFFERSIZE = 1048576 # 1 MB
|
||||
|
||||
def download!(source_url, destination_file)
|
||||
# For now we read the contents of one into a buffer
|
||||
# and copy it into the other. In the future, we should do
|
||||
# a system-level file copy (FileUtils.cp).
|
||||
open(source_url) do |f|
|
||||
loop do
|
||||
break if f.eof?
|
||||
destination_file.write(f.read(BUFFERSIZE))
|
||||
end
|
||||
end
|
||||
FileUtils.cp(source_url, destination_file.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,25 +7,10 @@ class FileDownloaderTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "downloading" do
|
||||
setup do
|
||||
@file = mock("file")
|
||||
@file.stubs(:read)
|
||||
@file.stubs(:eof?).returns(false)
|
||||
@downloader.stubs(:open).yields(@file)
|
||||
end
|
||||
|
||||
should "open with the given uri" do
|
||||
@downloader.expects(:open).with(@uri).once
|
||||
@downloader.download!(@uri, @tempfile)
|
||||
end
|
||||
|
||||
should "buffer the read from the file and write to the tempfile" do
|
||||
data = mock("data")
|
||||
write_seq = sequence("write_seq")
|
||||
@file.stubs(:eof?).returns(false).in_sequence(write_seq)
|
||||
@file.expects(:read).returns(data).in_sequence(write_seq)
|
||||
@tempfile.expects(:write).with(data).in_sequence(write_seq)
|
||||
@file.stubs(:eof?).returns(true).in_sequence(write_seq)
|
||||
should "cp the file" do
|
||||
path = '/path'
|
||||
@tempfile.expects(:path).returns(path)
|
||||
FileUtils.expects(:cp).with(@uri, path)
|
||||
@downloader.download!(@uri, @tempfile)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue