Skip to content

Commit fb9d753

Browse files
eileencodesparacycle
authored andcommitted
[ruby/rubygems] Remove verify_gz
This PR removes the `#verify_gz` method because it is redunant and unnecessary. Previously the `data.tar.gz` would get read twice for every file - once in `verify_gz` and once in `extract_files`. The `extract_files` method verifies the `data.tar.gz` when it reads it, and raises an error if unzipping it fails. The `verify_gz` code can be seen in some profiles as a hotspot - although not major - as it accounts for between 9% and 17% of time, but only when the installation thread doesn't have native extensions or plugins. ruby/rubygems@737c82986c
1 parent a33fde1 commit fb9d753

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

lib/rubygems/package.rb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def normalize_path(pathname) # :nodoc:
532532
##
533533
# Loads a Gem::Specification from the TarEntry +entry+
534534

535-
def load_spec(entry) # :nodoc:
535+
def load_spec_from_metadata(entry) # :nodoc:
536536
limit = 10 * 1024 * 1024
537537
case entry.full_name
538538
when "metadata" then
@@ -678,12 +678,7 @@ def verify_entry(entry)
678678
digest entry
679679
end
680680

681-
case file_name
682-
when "metadata", "metadata.gz" then
683-
load_spec entry
684-
when "data.tar.gz" then
685-
verify_gz entry
686-
end
681+
load_spec_from_metadata entry
687682
rescue StandardError
688683
warn "Exception while verifying #{@gem.path}"
689684
raise
@@ -711,18 +706,6 @@ def verify_files(gem)
711706
end
712707
end
713708

714-
##
715-
# Verifies that +entry+ is a valid gzipped file.
716-
717-
def verify_gz(entry) # :nodoc:
718-
Zlib::GzipReader.wrap entry do |gzio|
719-
# TODO: read into a buffer once zlib supports it
720-
gzio.read 16_384 until gzio.eof? # gzip checksum verification
721-
end
722-
rescue Zlib::GzipFile::Error => e
723-
raise Gem::Package::FormatError.new(e.message, entry.full_name)
724-
end
725-
726709
if RUBY_ENGINE == "truffleruby"
727710
def copy_stream(src, dst, size) # :nodoc:
728711
dst.write src.read(size)

test/rubygems/test_gem_package.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,15 +858,15 @@ def test_install_location_suffix
858858
"#{@destination} is not allowed", e.message)
859859
end
860860

861-
def test_load_spec
861+
def test_load_spec_from_metadata
862862
entry = StringIO.new Gem::Util.gzip @spec.to_yaml
863863
def entry.full_name
864864
"metadata.gz"
865865
end
866866

867867
package = Gem::Package.new "nonexistent.gem"
868868

869-
spec = package.load_spec entry
869+
spec = package.load_spec_from_metadata entry
870870

871871
assert_equal @spec, spec
872872
end

0 commit comments

Comments
 (0)