def extract
if @paths.empty?
@paths[nil] = FromPath.new(self, nil)
end
mkpath target.to_s
if zip_file.to_s.match /\.t?gz$/
Zlib::GzipReader.open(zip_file.to_s) { |tar|
Archive::Tar::Minitar::Input.open(tar) do |inp|
inp.each do |tar_entry|
@paths.each do |path, patterns|
patterns.map([tar_entry]).each do |dest, entry|
next if entry.directory?
dest = File.expand_path(dest, target.to_s)
trace "Extracting #{dest}"
mkpath File.dirname(dest) rescue nil
File.open(dest, 'wb') {|f| f.write entry.read}
end
end
end
end
}
else
Zip::ZipFile.open(zip_file.to_s) do |zip|
entries = zip.collect
@paths.each do |path, patterns|
patterns.map(entries).each do |dest, entry|
next if entry.directory?
dest = File.expand_path(dest, target.to_s)
trace "Extracting #{dest}"
mkpath File.dirname(dest) rescue nil
entry.restore_permissions = true
entry.extract(dest) { true }
end
end
end
end
touch target.to_s
end