Sha256: 119d75978d7e7ecaf9d618d11dc34685295cc7425f1b1c9aca2bee2c8c63dba0

Contents?: true

Size: 1.78 KB

Versions: 186

Compression:

Stored size: 1.78 KB

Contents

require 'puppet/util/checksums'
require 'puppet/type/file/data_sync'

module Puppet
  Puppet::Type.type(:file).newproperty(:checksum_value) do
    include Puppet::Util::Checksums
    include Puppet::DataSync

    desc "The checksum of the source contents. Only md5 and sha256 are supported when
      specifying this parameter. If this parameter is set, source_permissions will be
      assumed to be false, and ownership and permissions will not be read from source."

    def insync?(is)
      # If checksum_value and source are specified, manage the file contents.
      # Otherwise the content property will manage syncing.
      if resource.parameter(:source).nil?
        return true
      end

      checksum_insync?(resource.parameter(:source), is, true) {|_is| super(_is)}
    end

    def property_matches?(current, desired)
      return true if super(current, desired)
      return date_matches?(resource.parameter(:checksum).value, current, desired)
    end

    def retrieve
      # If checksum_value and source are specified, manage the file contents.
      # Otherwise the content property will manage syncing. Don't compute the checksum twice.
      if resource.parameter(:source).nil?
        return nil
      end

      result = retrieve_checksum(resource)
      # If the returned type matches the util/checksums format (prefixed with the type),
      # strip the checksum type.
      result = sumdata(result) if checksum?(result)
      result
    end

    def sync
      if resource.parameter(:source).nil?
        devfail "checksum_value#sync should not be called without a source parameter"
      end

      # insync? only returns false if it expects to manage the file content,
      # so instruct the resource to write its contents.
      contents_sync(resource.parameter(:source))
    end

  end
end

Version data entries

186 entries across 186 versions & 3 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/type/file/checksum_value.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/type/file/checksum_value.rb
puppet-5.3.7 lib/puppet/type/file/checksum_value.rb
puppet-5.3.7-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-5.3.7-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-5.3.7-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-4.10.12 lib/puppet/type/file/checksum_value.rb
puppet-4.10.12-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-4.10.12-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-4.10.12-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-4.10.11 lib/puppet/type/file/checksum_value.rb
puppet-4.10.11-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-4.10.11-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-4.10.11-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-5.3.6 lib/puppet/type/file/checksum_value.rb
puppet-5.3.6-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-5.3.6-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-5.3.6-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-5.3.5 lib/puppet/type/file/checksum_value.rb
puppet-5.3.5-x86-mingw32 lib/puppet/type/file/checksum_value.rb