Extracts all the files in the gzipped tar archive io into
destination_dir.
If an entry in the archive contains a relative path above
destination_dir or an absolute path is encountered an exception is
raised.
If pattern is specified, only entries matching that glob will be
extracted.
# File lib/rubygems/package.rb, line 348
def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc:
open_tar_gz io do |tar|
tar.each do |entry|
next unless File.fnmatch pattern, entry.full_name, File::FNM_DOTMATCH
destination = install_location entry.full_name, destination_dir
FileUtils.rm_rf destination
mkdir_options = {}
mkdir_options[:mode] = entry.header.mode if entry.directory?
mkdir =
if entry.directory? then
destination
else
File.dirname destination
end
FileUtils.mkdir_p mkdir, mkdir_options
open destination, 'wb' do |out|
out.write entry.read
FileUtils.chmod entry.header.mode, destination
end if entry.file?
verbose destination
end
end
end