Module: Puppet::Util::Checksums
- Included in:
- FileBucketFile::File, FileServing::Metadata
- Defined in:
- lib/puppet/util/checksums.rb
Overview
A stand-alone module for calculating checksums in a generic way.
Defined Under Namespace
Classes: FakeChecksum
Instance Method Summary collapse
-
#checksum?(string) ⇒ Boolean
Is the provided string a checksum?.
- #ctime(content) ⇒ Object
-
#ctime_file(filename) ⇒ Object
Return the :ctime of a file.
-
#md5(content) ⇒ Object
Calculate a checksum using Digest::MD5.
-
#md5_file(filename, lite = false) ⇒ Object
Calculate a checksum of a file’s content using Digest::MD5.
- #md5_stream {|digest| ... } ⇒ Object (also: #md5lite_stream)
-
#md5lite(content) ⇒ Object
Calculate a checksum of the first 500 chars of the content using Digest::MD5.
-
#md5lite_file(filename) ⇒ Object
Calculate a checksum of the first 500 chars of a file’s content using Digest::MD5.
- #mtime(content) ⇒ Object
-
#mtime_file(filename) ⇒ Object
Return the :mtime timestamp of a file.
-
#mtime_stream {|noop_digest| ... } ⇒ Object
(also: #ctime_stream)
by definition this doesn’t exist but we still need to execute the block given.
- #none(content) ⇒ Object
-
#none_file(filename) ⇒ Object
Return a “no checksum”.
- #none_stream {|noop_digest| ... } ⇒ Object
-
#sha1(content) ⇒ Object
Calculate a checksum using Digest::SHA1.
-
#sha1_file(filename, lite = false) ⇒ Object
Calculate a checksum of a file’s content using Digest::SHA1.
- #sha1_stream {|digest| ... } ⇒ Object (also: #sha1lite_stream)
-
#sha1lite(content) ⇒ Object
Calculate a checksum of the first 500 chars of the content using Digest::SHA1.
-
#sha1lite_file(filename) ⇒ Object
Calculate a checksum of the first 500 chars of a file’s content using Digest::SHA1.
-
#sumdata(checksum) ⇒ Object
Strip the checksum type from an existing checksum.
-
#sumtype(checksum) ⇒ Object
Strip the checksum type from an existing checksum.
Instance Method Details
#checksum?(string) ⇒ Boolean
Is the provided string a checksum?
11 12 13 |
# File 'lib/puppet/util/checksums.rb', line 11 def checksum?(string) string =~ /^\{(\w{3,5})\}\S+/ end |
#ctime(content) ⇒ Object
115 116 117 |
# File 'lib/puppet/util/checksums.rb', line 115 def ctime(content) "" end |
#ctime_file(filename) ⇒ Object
Return the :ctime of a file.
109 110 111 |
# File 'lib/puppet/util/checksums.rb', line 109 def ctime_file(filename) File.stat(filename).send(:ctime) end |
#md5(content) ⇒ Object
Calculate a checksum using Digest::MD5.
26 27 28 29 |
# File 'lib/puppet/util/checksums.rb', line 26 def md5(content) require 'digest/md5' Digest::MD5.hexdigest(content) end |
#md5_file(filename, lite = false) ⇒ Object
Calculate a checksum of a file’s content using Digest::MD5.
37 38 39 40 41 42 |
# File 'lib/puppet/util/checksums.rb', line 37 def md5_file(filename, lite = false) require 'digest/md5' digest = Digest::MD5.new checksum_file(digest, filename, lite) end |
#md5_stream {|digest| ... } ⇒ Object Also known as: md5lite_stream
49 50 51 52 53 54 |
# File 'lib/puppet/util/checksums.rb', line 49 def md5_stream(&block) require 'digest/md5' digest = Digest::MD5.new yield digest digest.hexdigest end |
#md5lite(content) ⇒ Object
Calculate a checksum of the first 500 chars of the content using Digest::MD5.
32 33 34 |
# File 'lib/puppet/util/checksums.rb', line 32 def md5lite(content) md5(content[0..511]) end |
#md5lite_file(filename) ⇒ Object
Calculate a checksum of the first 500 chars of a file’s content using Digest::MD5.
45 46 47 |
# File 'lib/puppet/util/checksums.rb', line 45 def md5lite_file(filename) md5_file(filename, true) end |
#mtime(content) ⇒ Object
71 72 73 |
# File 'lib/puppet/util/checksums.rb', line 71 def mtime(content) "" end |
#mtime_file(filename) ⇒ Object
Return the :mtime timestamp of a file.
59 60 61 |
# File 'lib/puppet/util/checksums.rb', line 59 def mtime_file(filename) File.stat(filename).send(:mtime) end |
#mtime_stream {|noop_digest| ... } ⇒ Object Also known as: ctime_stream
by definition this doesn’t exist but we still need to execute the block given
65 66 67 68 69 |
# File 'lib/puppet/util/checksums.rb', line 65 def mtime_stream noop_digest = FakeChecksum.new yield noop_digest nil end |
#none(content) ⇒ Object
130 131 132 |
# File 'lib/puppet/util/checksums.rb', line 130 def none(content) "" end |
#none_file(filename) ⇒ Object
Return a “no checksum”
120 121 122 |
# File 'lib/puppet/util/checksums.rb', line 120 def none_file(filename) "" end |
#none_stream {|noop_digest| ... } ⇒ Object
124 125 126 127 128 |
# File 'lib/puppet/util/checksums.rb', line 124 def none_stream noop_digest = FakeChecksum.new yield noop_digest "" end |
#sha1(content) ⇒ Object
Calculate a checksum using Digest::SHA1.
76 77 78 79 |
# File 'lib/puppet/util/checksums.rb', line 76 def sha1(content) require 'digest/sha1' Digest::SHA1.hexdigest(content) end |
#sha1_file(filename, lite = false) ⇒ Object
Calculate a checksum of a file’s content using Digest::SHA1.
87 88 89 90 91 92 |
# File 'lib/puppet/util/checksums.rb', line 87 def sha1_file(filename, lite = false) require 'digest/sha1' digest = Digest::SHA1.new checksum_file(digest, filename, lite) end |
#sha1_stream {|digest| ... } ⇒ Object Also known as: sha1lite_stream
99 100 101 102 103 104 |
# File 'lib/puppet/util/checksums.rb', line 99 def sha1_stream require 'digest/sha1' digest = Digest::SHA1.new yield digest digest.hexdigest end |
#sha1lite(content) ⇒ Object
Calculate a checksum of the first 500 chars of the content using Digest::SHA1.
82 83 84 |
# File 'lib/puppet/util/checksums.rb', line 82 def sha1lite(content) sha1(content[0..511]) end |
#sha1lite_file(filename) ⇒ Object
Calculate a checksum of the first 500 chars of a file’s content using Digest::SHA1.
95 96 97 |
# File 'lib/puppet/util/checksums.rb', line 95 def sha1lite_file(filename) sha1_file(filename, true) end |
#sumdata(checksum) ⇒ Object
Strip the checksum type from an existing checksum
16 17 18 |
# File 'lib/puppet/util/checksums.rb', line 16 def sumdata(checksum) checksum =~ /^\{(\w+)\}(.+)/ ? $2 : nil end |
#sumtype(checksum) ⇒ Object
Strip the checksum type from an existing checksum
21 22 23 |
# File 'lib/puppet/util/checksums.rb', line 21 def sumtype(checksum) checksum =~ /^\{(\w+)\}/ ? $1 : nil end |