Sha256: a3ed817b1363d053322bb52a004fa34a1a7513e48be6c1fd1ab2196f8f089834

Contents?: true

Size: 1.88 KB

Versions: 20

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true
require_relative '../../../puppet/util/checksums'
require_relative '../../../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, sha256, sha224, sha384 and sha512
      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

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.3.0 lib/puppet/type/file/checksum_value.rb
puppet-8.3.0-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.3.0-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.3.0-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-8.3.1 lib/puppet/type/file/checksum_value.rb
puppet-8.3.1-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.3.1-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.3.1-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-8.2.0 lib/puppet/type/file/checksum_value.rb
puppet-8.2.0-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.2.0-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.2.0-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-8.1.0 lib/puppet/type/file/checksum_value.rb
puppet-8.1.0-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.1.0-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.1.0-universal-darwin lib/puppet/type/file/checksum_value.rb
puppet-8.0.1 lib/puppet/type/file/checksum_value.rb
puppet-8.0.1-x86-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.0.1-x64-mingw32 lib/puppet/type/file/checksum_value.rb
puppet-8.0.1-universal-darwin lib/puppet/type/file/checksum_value.rb