class Chef::Resource::ArchiveFile

Public Instance Methods

archive_differs_from_disk?(src, dest) click to toggle source

try to determine if the resource has updated or not by checking for files that are in the archive, but not on disk or files with a non-matching mtime

@param [String] src @param [String] dest

@return [Boolean]

# File lib/chef/resource/archive_file.rb, line 125
def archive_differs_from_disk?(src, dest)
  require "ffi-libarchive"

  modified = false
  Dir.chdir(dest) do
    archive = Archive::Reader.open_filename(src)
    Chef::Log.trace("Beginning the comparison of file mtime between contents of #{src} and #{dest}")
    archive.each_entry do |e|
      pathname = ::File.expand_path(e.pathname)
      if ::File.exist?(pathname)
        Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}")
        modified = true unless ::File.mtime(pathname) == e.mtime
      else
        Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive")
        modified = true
      end
    end
  end
  modified
end
extract(src, dest, options = []) click to toggle source

extract the archive

@param [String] src @param [String] dest @param [Array] options

@return [void]

# File lib/chef/resource/archive_file.rb, line 153
def extract(src, dest, options = [])
  require "ffi-libarchive"

  converge_by("extract #{src} to #{dest}") do
    flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|)

    Dir.chdir(dest) do
      archive = Archive::Reader.open_filename(src)

      archive.each_entry do |e|
        archive.extract(e, flags.to_i)
      end
      archive.close
    end
  end
end
extract_option_map() click to toggle source

This can't be a constant since we might not have required 'ffi-libarchive' yet.

# File lib/chef/resource/archive_file.rb, line 104
def extract_option_map
  {
    owner: Archive::EXTRACT_OWNER,
    permissions: Archive::EXTRACT_PERM,
    time: Archive::EXTRACT_TIME,
    no_overwrite: Archive::EXTRACT_NO_OVERWRITE,
    acl: Archive::EXTRACT_ACL,
    fflags: Archive::EXTRACT_FFLAGS,
    extended_information: Archive::EXTRACT_XATTR,
    xattr: Archive::EXTRACT_XATTR,
    no_overwrite_newer: Archive::EXTRACT_NO_OVERWRITE_NEWER,
  }
end