Sha256: 1c3b1b8465e9e9b3024751a3bd7a4a2ffd950beb3c176a7b500e7e6d5873d6c3

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

require 'puppet/configurer'
require 'puppet/resource/catalog'
require 'puppet/util/config_timeout'

class Puppet::Configurer::Downloader
  extend Puppet::Util::ConfigTimeout
  
  attr_reader :name, :path, :source, :ignore

  # Evaluate our download, returning the list of changed values.
  def evaluate
    Puppet.info "Retrieving #{name}"

    files = []
    begin
      ::Timeout.timeout(self.class.timeout_interval) do
        catalog.apply do |trans|
          trans.changed?.find_all do |resource|
            yield resource if block_given?
            files << resource[:path]
          end
        end
      end
    rescue Puppet::Error, Timeout::Error => detail
      Puppet.log_exception(detail, "Could not retrieve #{name}: #{detail}")
    end

    files
  end

  def initialize(name, path, source, ignore = nil, environment = nil)
    @name, @path, @source, @ignore, @environment = name, path, source, ignore, environment
  end

  def catalog
    catalog = Puppet::Resource::Catalog.new
    catalog.host_config = false
    catalog.add_resource(file)
    catalog.environment = @environment
    catalog
  end

  def file
    args = default_arguments.merge(:path => path, :source => source)
    args[:ignore] = ignore.split if ignore
    Puppet::Type.type(:file).new(args)
  end

  private

  require 'sys/admin' if Puppet.features.microsoft_windows?

  def default_arguments
    {
      :path => path,
      :recurse => true,
      :source => source,
      :tag => name,
      :purge => true,
      :force => true,
      :backup => false,
      :noop => false
    }.merge(
      Puppet.features.microsoft_windows? ? {} :
      {
        :owner => Process.uid,
        :group => Process.gid
      }
    )
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
puppet-3.0.0.rc5 lib/puppet/configurer/downloader.rb
puppet-3.0.0.rc4 lib/puppet/configurer/downloader.rb