summaryrefslogtreecommitdiff
path: root/lib/rubygems/package
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-30 13:01:35 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-30 13:01:35 +0000
commit8da8d4b043c37b53a69803c71ff36b478d4776d0 (patch)
tree7c8cec15645e74f19c88e4eb5b210b96174c7d03 /lib/rubygems/package
parentc5cb386eba6d9a2d9a8e6ffa8c30137d0c4660c1 (diff)
downloadruby-8da8d4b043c37b53a69803c71ff36b478d4776d0.tar.gz
Merge RubyGems 3.0.0.beta1.
* It drop to support < Ruby 2.2 * Cleanup deprecated methods and classes. * Mark obsoleted methods to deprecate. * and other enhancements. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/package')
-rw-r--r--lib/rubygems/package/old.rb14
-rw-r--r--lib/rubygems/package/tar_header.rb4
-rw-r--r--lib/rubygems/package/tar_reader.rb2
-rw-r--r--lib/rubygems/package/tar_reader/entry.rb2
-rw-r--r--lib/rubygems/package/tar_test_case.rb8
-rw-r--r--lib/rubygems/package/tar_writer.rb12
6 files changed, 12 insertions, 30 deletions
diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb
index 322d682ca8..a8457948ff 100644
--- a/lib/rubygems/package/old.rb
+++ b/lib/rubygems/package/old.rb
@@ -78,9 +78,9 @@ class Gem::Package::Old < Gem::Package
FileUtils.rm_rf destination
- FileUtils.mkdir_p File.dirname destination
+ FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0700
- File.open destination, 'wb', entry['mode'] do |out|
+ File.open destination, 'wb', file_mode(entry['mode']) do |out|
out.write file_data
end
@@ -144,17 +144,9 @@ class Gem::Package::Old < Gem::Package
end
end
- yaml_error = if RUBY_VERSION < '1.9' then
- YAML::ParseError
- elsif YAML.const_defined?(:ENGINE) && YAML::ENGINE.yamler == 'syck' then
- YAML::ParseError
- else
- YAML::SyntaxError
- end
-
begin
@spec = Gem::Specification.from_yaml yaml
- rescue yaml_error
+ rescue YAML::SyntaxError
raise Gem::Exception, "Failed to parse gem specification out of gem file"
end
rescue ArgumentError
diff --git a/lib/rubygems/package/tar_header.rb b/lib/rubygems/package/tar_header.rb
index d557357114..fa1f5b6e46 100644
--- a/lib/rubygems/package/tar_header.rb
+++ b/lib/rubygems/package/tar_header.rb
@@ -94,12 +94,14 @@ class Gem::Package::TarHeader
attr_reader(*FIELDS)
+ EMPTY_HEADER = ("\0" * 512).freeze # :nodoc:
+
##
# Creates a tar header from IO +stream+
def self.from(stream)
header = stream.read 512
- empty = (header == "\0" * 512)
+ empty = (EMPTY_HEADER == header)
fields = header.unpack UNPACK_FORMAT
diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb
index 1098336e36..d00f89e7f6 100644
--- a/lib/rubygems/package/tar_reader.rb
+++ b/lib/rubygems/package/tar_reader.rb
@@ -93,10 +93,8 @@ class Gem::Package::TarReader
def rewind
if @init_pos == 0 then
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :rewind
@io.rewind
else
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
@io.pos = @init_pos
end
end
diff --git a/lib/rubygems/package/tar_reader/entry.rb b/lib/rubygems/package/tar_reader/entry.rb
index 5f958edc2f..b6fb8c3a3a 100644
--- a/lib/rubygems/package/tar_reader/entry.rb
+++ b/lib/rubygems/package/tar_reader/entry.rb
@@ -145,8 +145,6 @@ class Gem::Package::TarReader::Entry
def rewind
check_closed
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
-
@io.pos = @orig_pos
@read = 0
end
diff --git a/lib/rubygems/package/tar_test_case.rb b/lib/rubygems/package/tar_test_case.rb
index 46ac949587..381a5d0f43 100644
--- a/lib/rubygems/package/tar_test_case.rb
+++ b/lib/rubygems/package/tar_test_case.rb
@@ -94,13 +94,7 @@ class Gem::Package::TarTestCase < Gem::TestCase
ASCIIZ(dname, 155) # char prefix[155]; ASCII + (Z unless filled)
]
- format = "C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155"
- h = if RUBY_VERSION >= "1.9" then
- arr.join
- else
- arr = arr.join("").split(//).map{|x| x[0]}
- arr.pack format
- end
+ h = arr.join
ret = h + "\0" * (512 - h.size)
assert_equal(512, ret.size)
ret
diff --git a/lib/rubygems/package/tar_writer.rb b/lib/rubygems/package/tar_writer.rb
index 390f7851a3..a2dbab9f2f 100644
--- a/lib/rubygems/package/tar_writer.rb
+++ b/lib/rubygems/package/tar_writer.rb
@@ -106,12 +106,10 @@ class Gem::Package::TarWriter
def add_file(name, mode) # :yields: io
check_closed
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
-
name, prefix = split_name name
init_pos = @io.pos
- @io.write "\0" * 512 # placeholder for the header
+ @io.write Gem::Package::TarHeader::EMPTY_HEADER # placeholder for the header
yield RestrictedStream.new(@io) if block_given?
@@ -125,7 +123,7 @@ class Gem::Package::TarWriter
header = Gem::Package::TarHeader.new :name => name, :mode => mode,
:size => size, :prefix => prefix,
- :mtime => Time.now
+ :mtime => ENV["SOURCE_DATE_EPOCH"] ? Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc : Time.now
@io.write header
@io.pos = final_pos
@@ -220,7 +218,7 @@ class Gem::Package::TarWriter
header = Gem::Package::TarHeader.new(:name => name, :mode => mode,
:size => size, :prefix => prefix,
- :mtime => Time.now).to_s
+ :mtime => ENV["SOURCE_DATE_EPOCH"] ? Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc : Time.now).to_s
@io.write header
os = BoundedStream.new @io, size
@@ -248,7 +246,7 @@ class Gem::Package::TarWriter
:size => 0, :typeflag => "2",
:linkname => target,
:prefix => prefix,
- :mtime => Time.now).to_s
+ :mtime => ENV["SOURCE_DATE_EPOCH"] ? Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc : Time.now).to_s
@io.write header
@@ -301,7 +299,7 @@ class Gem::Package::TarWriter
header = Gem::Package::TarHeader.new :name => name, :mode => mode,
:typeflag => "5", :size => 0,
:prefix => prefix,
- :mtime => Time.now
+ :mtime => ENV["SOURCE_DATE_EPOCH"] ? Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc : Time.now
@io.write header