summaryrefslogtreecommitdiff
path: root/lib/rubygems/remote_fetcher.rb
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-19 00:08:49 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-19 00:08:49 +0000
commite798ccbacf489a3af2201ae30058ff0ae7f79045 (patch)
tree4147a7834eb88323057fd2120a2ddc96c1eb32ab /lib/rubygems/remote_fetcher.rb
parentd26fb035cae8d351dc238376722c980230dc5fbd (diff)
Import rubygems 1.5.0 (release candidate)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/remote_fetcher.rb')
-rw-r--r--lib/rubygems/remote_fetcher.rb63
1 files changed, 54 insertions, 9 deletions
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
index 07cd55b161..aa63392848 100644
--- a/lib/rubygems/remote_fetcher.rb
+++ b/lib/rubygems/remote_fetcher.rb
@@ -1,9 +1,12 @@
-require 'net/http'
-require 'stringio'
-require 'time'
-require 'uri'
+######################################################################
+# This file is imported from the rubygems project.
+# DO NOT make modifications in this repo. They _will_ be reverted!
+# File a patch instead and assign it to Ryan Davis or Eric Hodel.
+######################################################################
require 'rubygems'
+require 'rubygems/user_interaction'
+require 'uri'
##
# RemoteFetcher handles the details of fetching gems and gem information from
@@ -56,6 +59,11 @@ class Gem::RemoteFetcher
# * <tt>:no_proxy</tt>: ignore environment variables and _don't_ use a proxy
def initialize(proxy = nil)
+ require 'net/http'
+ require 'stringio'
+ require 'time'
+ require 'uri'
+
Socket.do_not_reverse_lookup = true
@connections = {}
@@ -75,6 +83,8 @@ class Gem::RemoteFetcher
# always replaced.
def download(spec, source_uri, install_dir = Gem.dir)
+ Gem.ensure_gem_subdirectories(install_dir) rescue nil
+
if File.writable?(install_dir)
cache_dir = File.join install_dir, 'cache'
else
@@ -147,7 +157,7 @@ class Gem::RemoteFetcher
source_uri.path
end
- source_path = URI.unescape source_path
+ source_path = unescape source_path
begin
FileUtils.cp source_path, local_gem_path unless
@@ -191,12 +201,20 @@ class Gem::RemoteFetcher
def escape(str)
return unless str
- URI.escape(str)
+ @uri_parser ||= uri_escaper
+ @uri_parser.escape str
end
def unescape(str)
return unless str
- URI.unescape(str)
+ @uri_parser ||= uri_escaper
+ @uri_parser.unescape str
+ end
+
+ def uri_escaper
+ URI::Parser.new
+ rescue NameError
+ URI
end
##
@@ -241,7 +259,7 @@ class Gem::RemoteFetcher
]
end
- connection_id = net_http_args.join ':'
+ connection_id = [Thread.current.object_id, *net_http_args].join ':'
@connections[connection_id] ||= Net::HTTP.new(*net_http_args)
connection = @connections[connection_id]
@@ -339,7 +357,34 @@ class Gem::RemoteFetcher
say "#{request.method} #{uri}" if
Gem.configuration.really_verbose
- response = connection.request request
+
+ file_name = File.basename(uri.path)
+ # perform download progress reporter only for gems
+ if request.response_body_permitted? && file_name =~ /\.gem$/
+ reporter = ui.download_reporter
+ response = connection.request(request) do |incomplete_response|
+ if Net::HTTPOK === incomplete_response
+ reporter.fetch(file_name, incomplete_response.content_length)
+ downloaded = 0
+ data = ''
+
+ incomplete_response.read_body do |segment|
+ data << segment
+ downloaded += segment.length
+ reporter.update(downloaded)
+ end
+ reporter.done
+ if incomplete_response.respond_to? :body=
+ incomplete_response.body = data
+ else
+ incomplete_response.instance_variable_set(:@body, data)
+ end
+ end
+ end
+ else
+ response = connection.request request
+ end
+
say "#{response.code} #{response.message}" if
Gem.configuration.really_verbose