Sha256: 7555575d1bb6ca85b81d3ec4b797c590c0609f00bfaf3d00482ebb4e8e09c3e2

Contents?: true

Size: 1.19 KB

Versions: 491

Compression:

Stored size: 1.19 KB

Contents

require 'digest/md5'
require 'puppet/network/format_support'

module Puppet::ModuleTool

  # = Checksums
  #
  # This class provides methods for generating checksums for data and adding
  # them to +Metadata+.
  class Checksums
    include Puppet::Network::FormatSupport
    include Enumerable

    # Instantiate object with string +path+ to create checksums from.
    def initialize(path)
      @path = Pathname.new(path)
    end

    # Return checksum for the +Pathname+.
    def checksum(pathname)
      return Digest::MD5.hexdigest(Puppet::FileSystem.binread(pathname))
    end

    # Return checksums for object's +Pathname+, generate if it's needed.
    # Result is a hash of path strings to checksum strings.
    def data
      unless @data
        @data = {}
        @path.find do |descendant|
          if Puppet::ModuleTool.artifact?(descendant)
            Find.prune
          elsif descendant.file?
            path = descendant.relative_path_from(@path)
            @data[path.to_s] = checksum(descendant)
          end
        end
      end
      return @data
    end

    alias :to_data_hash :data
    alias :to_hash :data

    # TODO: Why?
    def each(&block)
      data.each(&block)
    end
  end
end

Version data entries

491 entries across 491 versions & 3 rubygems

Version Path
puppet-6.29.0 lib/puppet/module_tool/checksums.rb
puppet-6.29.0-x86-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.29.0-x64-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.29.0-universal-darwin lib/puppet/module_tool/checksums.rb
puppet-6.28.0 lib/puppet/module_tool/checksums.rb
puppet-6.28.0-x86-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.28.0-x64-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.28.0-universal-darwin lib/puppet/module_tool/checksums.rb
puppet-6.27.0 lib/puppet/module_tool/checksums.rb
puppet-6.27.0-x86-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.27.0-x64-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.27.0-universal-darwin lib/puppet/module_tool/checksums.rb
puppet-6.26.0 lib/puppet/module_tool/checksums.rb
puppet-6.26.0-x86-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.26.0-x64-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.26.0-universal-darwin lib/puppet/module_tool/checksums.rb
puppet-6.25.1 lib/puppet/module_tool/checksums.rb
puppet-6.25.1-x86-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.25.1-x64-mingw32 lib/puppet/module_tool/checksums.rb
puppet-6.25.1-universal-darwin lib/puppet/module_tool/checksums.rb