Module: FileType::ExtractableDir

Defined in:
lib/file_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.longest_common_path(log) ⇒ Object

We want the longest common path



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/file_type.rb', line 200

def longest_common_path ( log )
  longest = nil
  raise CorruptedTarballError, 'tar output empty' if log.zero?
  log.each_line do |line|
    line.chomp!
    path = line.split(/\//)
    longest = path if longest.nil?
    longest &= path
    raise CorruptedTarballError, log.read if longest.empty?
  end
  raise CorruptedTarballError, log.read if longest.nil?
  longest
end

Instance Method Details

#extractObject



194
195
196
197
# File 'lib/file_type.rb', line 194

def extract
  dir = extract_extractable
  FileType.guess(dir.path + longest_common_path(@log).join('/'))
end

#mk_cmd(out) ⇒ Object



187
188
189
190
191
192
# File 'lib/file_type.rb', line 187

def mk_cmd ( out )
  @log = TempPath.new('log')
  cmd = extract_command[@tmp] < @path > @log
  @tmp.mkpath
  cmd
end