Class: FPM::Fry::Source::Archive::TarCache

Inherits:
Cache
  • Object
show all
Defined in:
lib/fpm/fry/source/archive.rb

Direct Known Subclasses

TarBz2Cache, TarGzCache

Instance Attribute Summary

Attributes inherited from Cache

#package, #tempdir

Instance Method Summary collapse

Methods inherited from Cache

#cachekey

Instance Method Details

#copy_to(dst) ⇒ Object



156
157
158
159
# File 'lib/fpm/fry/source/archive.rb', line 156

def copy_to(dst)
  update!
  Exec['tar','-xf',tempfile,'-C',dst, logger: logger]
end

#prefixObject



161
162
163
164
# File 'lib/fpm/fry/source/archive.rb', line 161

def prefix
  update!
  @prefix ||= prefix!
end

#prefix!Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/fpm/fry/source/archive.rb', line 166

def prefix!
  longest = nil
  Exec.popen('tar','-tf',tempfile, logger: logger).each_line.map do |line|
    line = line.chomp
    parts = line.split('/')
    parts.pop unless line[-1] == '/'
    if longest.nil?
      longest = parts
    else
      longest.each_with_index do | e, i |
        if parts[i] != e
          longest = longest[0...i]
          break
        end
      end
      break if longest.none?
    end
  end
  return Array(longest).join('/')
end

#tar_ioObject



151
152
153
154
# File 'lib/fpm/fry/source/archive.rb', line 151

def tar_io
  update!
  ioclass.open(tempfile)
end