diff --git a/lib/vagrant/downloaders/file.rb b/lib/vagrant/downloaders/file.rb index ca119d382..f63bc89c7 100644 --- a/lib/vagrant/downloaders/file.rb +++ b/lib/vagrant/downloaders/file.rb @@ -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 \ No newline at end of file +end diff --git a/test/vagrant/downloaders/file_test.rb b/test/vagrant/downloaders/file_test.rb index bcd52cc93..6e9f783f4 100644 --- a/test/vagrant/downloaders/file_test.rb +++ b/test/vagrant/downloaders/file_test.rb @@ -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