Author: assaf
Date: Tue Sep 23 18:04:52 2008
New Revision: 698409
URL: http://svn.apache.org/viewvc?rev=698409&view=rev
Log:
This might prevent progress bar from eating up all CPU all the time. Crossing
fingers.
Modified:
incubator/buildr/trunk/lib/buildr/core/progressbar.rb
incubator/buildr/trunk/lib/buildr/core/transports.rb
Modified: incubator/buildr/trunk/lib/buildr/core/progressbar.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/progressbar.rb?rev=698409&r1=698408&r2=698409&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/progressbar.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/progressbar.rb Tue Sep 23 18:04:52
2008
@@ -143,7 +143,7 @@
end
def changed?
- return false unless @output
+ return false unless @output && Time.now - @last_time > 0.1
return human(@count) != human(@previous) if @total == 0
return true if (@count - @previous) >= @total / 100
return Time.now - @last_time > 1
Modified: incubator/buildr/trunk/lib/buildr/core/transports.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/transports.rb?rev=698409&r1=698408&r2=698409&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/transports.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/transports.rb Tue Sep 23 18:04:52
2008
@@ -56,6 +56,9 @@
class NotFoundError < RuntimeError
end
+ # How many bytes to read/write at once.
+ RW_CHUNK_SIZE = 2 ** 20 #:nodoc:
+
class << self
# :call-seq:
@@ -340,7 +343,7 @@
connect do |http|
trace "Uploading to #{path}"
content = StringIO.new
- while chunk = yield(32 * 4096)
+ while chunk = yield(RW_CHUNK_SIZE)
content << chunk
end
headers = { 'Content-MD5'=>Digest::MD5.hexdigest(content.string) }
@@ -418,13 +421,13 @@
trace "Downloading to #{path}"
sftp.file.open(path, 'r') do |file|
if block
- while chunk = file.read(32 * 4096)
+ while chunk = file.read(RW_CHUNK_SIZE)
block.call chunk
progress << chunk
end
else
result = ''
- while chunk = file.read(32 * 4096)
+ while chunk = file.read(RW_CHUNK_SIZE)
result << chunk
progress << chunk
end
@@ -468,7 +471,7 @@
with_progress_bar options[:progress] && options[:size],
path.split('/'), options[:size] || 0 do |progress|
trace "Uploading to #{path}"
sftp.file.open(path, 'w') do |file|
- while chunk = yield(32 * 4096)
+ while chunk = yield(RW_CHUNK_SIZE)
file.write chunk
progress << chunk
end
@@ -555,7 +558,7 @@
Tempfile.open File.basename(path) do |temp|
temp.binmode
with_progress_bar options[:progress] && options[:size],
path.split('/'), options[:size] || 0 do |progress|
- while chunk = yield(32 * 4096)
+ while chunk = yield(RW_CHUNK_SIZE)
temp.write chunk
progress << chunk
end