Module: RHC::TarGz

Defined in:
lib/rhc/tar_gz.rb

Class Method Summary collapse

Class Method Details

.contains(filename, search, force_ruby = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rhc/tar_gz.rb', line 11

def self.contains(filename, search, force_ruby=false)
  
  return false if ! (File.file? filename and File.basename(filename).downcase =~ /.\.t(ar\.)?gz$/i)

  regex = Regexp.new search
  if RHC::Helpers.windows? or RHC::Helpers.mac? or force_ruby
    begin
      zlib::GzipReader.open(filename) do |gz|
        Minitar::Reader.open gz do |tar|
          tar.each_entry do |entry|
            if entry.full_name =~ regex
              return true
            end
          end
        end
      end
    rescue zlib::GzipFile::Error, zlib::GzipFile::Error
      false
    end
  else
    # combining STDOUT and STDERR (i.e., 2>&1) does not suppress output
    # when the specs run via 'bundle exec rake spec'
    system "#{TAR_BIN} --wildcards -tf '#{filename}' '#{regex.source}' 2>/dev/null >/dev/null"
  end
end