extract_tar_gz(io, destination_dir, pattern = "*")
public
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 385
def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
directories = [] if dir_mode
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] = dir_mode ? 0755 : (entry.header.mode if entry.directory?)
mkdir =
if entry.directory?
destination
else
File.dirname destination
end
directories << mkdir if directories
mkdir_p_safe mkdir, mkdir_options, destination_dir, entry.full_name
File.open destination, 'wb' do |out|
out.write entry.read
FileUtils.chmod file_mode(entry.header.mode), destination
end if entry.file?
File.symlink(entry.header.linkname, destination) if entry.symlink?
verbose destination
end
end
if directories
directories.uniq!
File.chmod(dir_mode, *directories)
end
end