Sha256: b8ded85c39674e1d8d67ba963ffe5caf95e0bbbfb559c169c01e68894d0c8788

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require 'app_info/dsym/debug_info'

module AppInfo
  # DSYM parser
  class DSYM < File
    include Helper::Archive

    def file_type
      Format::DSYM
    end

    def each_file(&block)
      files.each { |file| block.call(file) }
    end

    def files
      @files ||= Dir.children(contents).each_with_object([]) do |file, obj|
        obj << DebugInfo.new(::File.join(contents, file))
      end
    end

    def clear!
      return unless @contents

      FileUtils.rm_rf(@contents)

      @contents = nil
      @files = nil
    end

    def contents
      @contents ||= lambda {
        return @file if ::File.directory?(@file)

        dsym_filenames = []
        unarchive(@file, prefix: 'dsym') do |base_path, zip_file|
          zip_file.each do |entry|
            file_path = entry.name
            next unless file_path.downcase.include?('.dsym/contents/')
            next if ::File.basename(file_path).start_with?('.')

            dsym_filename = file_path.split('/').select { |f| f.downcase.end_with?('.dsym') }.last
            dsym_filenames << dsym_filename unless dsym_filenames.include?(dsym_filename)

            unless file_path.start_with?(dsym_filename)
              file_path = file_path.split('/')[1..-1].join('/')
            end

            dest_path = ::File.join(base_path, file_path)
            entry.extract(dest_path) unless ::File.exist?(dest_path)
          end
        end
      }.call
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
app-info-3.0.0.beta1 lib/app_info/dsym.rb