aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/package
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-14 03:30:02 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-14 03:30:02 +0000
commit4de117a61517e839f2c45eaf45d56fc243d6d5b2 (patch)
tree7cb5af7a7eb513e5dddf5e343746b1611e628387 /lib/rubygems/package
parente548c09d429a5136285ea81aed418685359ed124 (diff)
downloadruby-4de117a61517e839f2c45eaf45d56fc243d6d5b2.tar.gz
* lib/rubygems: Update to RubyGems 2.4.1 master(713ab65)
Complete history at: https://github.com/rubygems/rubygems/blob/master/History.txt#L3-L216 * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/package')
-rw-r--r--lib/rubygems/package/file_source.rb33
-rw-r--r--lib/rubygems/package/io_source.rb45
-rw-r--r--lib/rubygems/package/old.rb8
-rw-r--r--lib/rubygems/package/source.rb3
-rw-r--r--lib/rubygems/package/tar_reader/entry.rb2
5 files changed, 87 insertions, 4 deletions
diff --git a/lib/rubygems/package/file_source.rb b/lib/rubygems/package/file_source.rb
new file mode 100644
index 0000000000..85316f62e7
--- /dev/null
+++ b/lib/rubygems/package/file_source.rb
@@ -0,0 +1,33 @@
+##
+# The primary source of gems is a file on disk, including all usages
+# internal to rubygems.
+#
+# This is a private class, do not depend on it directly. Instead, pass a path
+# object to `Gem::Package.new`.
+
+class Gem::Package::FileSource < Gem::Package::Source # :nodoc: all
+
+ attr_reader :path
+
+ def initialize path
+ @path = path
+ end
+
+ def start
+ @start ||= File.read path, 20
+ end
+
+ def present?
+ File.exist? path
+ end
+
+ def with_write_io &block
+ open path, 'wb', &block
+ end
+
+ def with_read_io &block
+ open path, 'rb', &block
+ end
+
+end
+
diff --git a/lib/rubygems/package/io_source.rb b/lib/rubygems/package/io_source.rb
new file mode 100644
index 0000000000..f89593dd2d
--- /dev/null
+++ b/lib/rubygems/package/io_source.rb
@@ -0,0 +1,45 @@
+##
+# Supports reading and writing gems from/to a generic IO object. This is
+# useful for other applications built on top of rubygems, such as
+# rubygems.org.
+#
+# This is a private class, do not depend on it directly. Instead, pass an IO
+# object to `Gem::Package.new`.
+
+class Gem::Package::IOSource < Gem::Package::Source # :nodoc: all
+
+ attr_reader :io
+
+ def initialize io
+ @io = io
+ end
+
+ def start
+ @start ||= begin
+ if io.pos > 0
+ raise Gem::Package::Error, "Cannot read start unless IO is at start"
+ end
+
+ value = io.read 20
+ io.rewind
+ value
+ end
+ end
+
+ def present?
+ true
+ end
+
+ def with_read_io
+ yield io
+ end
+
+ def with_write_io
+ yield io
+ end
+
+ def path
+ end
+
+end
+
diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb
index 31c4111d33..65bcbb2283 100644
--- a/lib/rubygems/package/old.rb
+++ b/lib/rubygems/package/old.rb
@@ -37,7 +37,7 @@ class Gem::Package::Old < Gem::Package
return @contents if @contents
- open @gem, 'rb' do |io|
+ @gem.with_read_io do |io|
read_until_dashes io # spec
header = file_list io
@@ -53,7 +53,7 @@ class Gem::Package::Old < Gem::Package
errstr = "Error reading files from gem"
- open @gem, 'rb' do |io|
+ @gem.with_read_io do |io|
read_until_dashes io # spec
header = file_list io
raise Gem::Exception, errstr unless header
@@ -83,7 +83,7 @@ class Gem::Package::Old < Gem::Package
out.write file_data
end
- say destination if Gem.configuration.really_verbose
+ verbose destination
end
end
rescue Zlib::DataError
@@ -136,7 +136,7 @@ class Gem::Package::Old < Gem::Package
yaml = ''
- open @gem, 'rb' do |io|
+ @gem.with_read_io do |io|
skip_ruby io
read_until_dashes io do |line|
yaml << line
diff --git a/lib/rubygems/package/source.rb b/lib/rubygems/package/source.rb
new file mode 100644
index 0000000000..1f18d479da
--- /dev/null
+++ b/lib/rubygems/package/source.rb
@@ -0,0 +1,3 @@
+class Gem::Package::Source # :nodoc:
+end
+
diff --git a/lib/rubygems/package/tar_reader/entry.rb b/lib/rubygems/package/tar_reader/entry.rb
index 7034e59210..737c7639c6 100644
--- a/lib/rubygems/package/tar_reader/entry.rb
+++ b/lib/rubygems/package/tar_reader/entry.rb
@@ -129,6 +129,8 @@ class Gem::Package::TarReader::Entry
ret
end
+ alias readpartial read # :nodoc:
+
##
# Rewinds to the beginning of the tar file entry