Module: AppEntitlementsStatistics::Helper::Archive

Defined in:
lib/cocoapods-entitlements-statistics/app_entitlements_statistics/helper.rb

Instance Method Summary collapse

Instance Method Details

#tempdir(file, prefix:, system: false) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/helper.rb', line 73

def tempdir(file, prefix:, system: false)
    dest_path = if system
                    Dir.mktmpdir("appinfo-#{prefix}-#{File.basename(file, '.*')}-", '/tmp')
                else
                    File.join(File.dirname(file), prefix)
                end
    
    dest_file = File.join(dest_path, File.basename(file))
    FileUtils.mkdir_p(dest_path, mode: 0_700) unless system
    dest_file
end

#unarchive(file, path: nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/helper.rb', line 53

def unarchive(file, path: nil)
    path = path ? "#{path}-" : ''
    root_path = "#{Dir.mktmpdir}/AppInfo-#{path}#{SecureRandom.hex}"
    # puts root_path
    Zip::File.open(file) do |zip_file|
        if block_given?
            yield root_path, zip_file
        else
            zip_file.each do |f|
                f_path = File.join(root_path, f.name)
                FileUtils.mkdir_p(File.dirname(f_path))
                zip_file.extract(f, f_path) unless File.exist?(f_path)
            end
        end
    end
    
    root_path
end