Sha256: 7720cdb172aeaf6af34038c78a78e5ac321309e60a2f75a202a8f189cc13f9b4

Contents?: true

Size: 1.23 KB

Versions: 16

Compression:

Stored size: 1.23 KB

Contents

require 'digest/md5'

module Puppet::ModuleTool

  # = Checksums
  #
  # This class proides methods for generating checksums for data and adding
  # them to +Metadata+.
  class Checksums
    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(IO.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

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

    # Update +Metadata+'s checksums with this object's.
    def annotate(metadata)
      metadata.checksums.replace(data)
    end

    # TODO: Move the Checksummer#run checksum checking to here?

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
puppet-3.3.2 lib/puppet/module_tool/checksums.rb
puppet-3.3.1 lib/puppet/module_tool/checksums.rb
puppet-3.3.1.rc3 lib/puppet/module_tool/checksums.rb
puppet-3.3.1.rc2 lib/puppet/module_tool/checksums.rb
puppet-3.3.1.rc1 lib/puppet/module_tool/checksums.rb
puppet-3.3.0 lib/puppet/module_tool/checksums.rb
puppet-3.3.0.rc3 lib/puppet/module_tool/checksums.rb
puppet-3.3.0.rc2 lib/puppet/module_tool/checksums.rb
puppet-3.2.4 lib/puppet/module_tool/checksums.rb
puppet-3.2.3 lib/puppet/module_tool/checksums.rb
puppet-3.2.3.rc1 lib/puppet/module_tool/checksums.rb
puppet-3.2.2 lib/puppet/module_tool/checksums.rb
puppet-3.2.1 lib/puppet/module_tool/checksums.rb
puppet-3.2.1.rc1 lib/puppet/module_tool/checksums.rb
puppet-3.2.0.rc2 lib/puppet/module_tool/checksums.rb
puppet-3.2.0.rc1 lib/puppet/module_tool/checksums.rb