Skip to content

Commit

Permalink
Don't make duplicated checks on directory safety
Browse files Browse the repository at this point in the history
This seems to speed up `gem install` on Windows by more than 50%.
  • Loading branch information
deivid-rodriguez committed Oct 8, 2021
1 parent d9f99e4 commit 1970b12
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def extract_files(destination_dir, pattern = "*")
# extracted.

def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
directories = [] if dir_mode
directories = []
open_tar_gz io do |tar|
tar.each do |entry|
next unless File.fnmatch pattern, entry.full_name, File::FNM_DOTMATCH
Expand All @@ -417,9 +417,11 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
else
File.dirname destination
end
directories << mkdir if directories

mkdir_p_safe mkdir, mkdir_options, destination_dir, entry.full_name
unless directories.include?(mkdir)
mkdir_p_safe mkdir, mkdir_options, destination_dir, entry.full_name
directories << mkdir
end

File.open destination, 'wb' do |out|
out.write entry.read
Expand All @@ -432,8 +434,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
end
end

if directories
directories.uniq!
if dir_mode
File.chmod(dir_mode, *directories)
end
end
Expand Down

0 comments on commit 1970b12

Please sign in to comment.