diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb index 24bce1c7aa..d60d38484e 100644 --- a/lib/puppet/type/file/content.rb +++ b/lib/puppet/type/file/content.rb @@ -48,23 +48,19 @@ module Puppet if value == :absent value elsif value.is_a?(String) && checksum?(value) - # XXX This is potentially dangerous because it means users can't write a file whose - # entire contents are a plain checksum unless it is a Binary content. - Puppet.puppet_deprecation_warning([ - # TRANSLATORS "content" is an attribute and should not be translated - _('Using a checksum in a file\'s "content" property is deprecated.'), - # TRANSLATORS "filebucket" is a resource type and should not be translated. The quoted occurrence of "content" is an attribute and should not be translated. - _('The ability to use a checksum to retrieve content from the filebucket using the "content" property will be removed in a future release.'), - # TRANSLATORS "content" is an attribute and should not be translated. - _('The literal value of the "content" property will be written to the file.'), - # TRANSLATORS "static catalogs" should not be translated. - _('The checksum retrieval functionality is being replaced by the use of static catalogs.'), - _('See https://puppet.com/docs/puppet/latest/static_catalogs.html for more information.') - ].join(" "), - :file => @resource.file, - :line => @resource.line) if !@actual_content && !resource.parameter(:source) - value + # Our argument looks like a checksum. Is it the value of the content + # attribute in Puppet code, that happens to look like a checksum, or is + # it an actual checksum computed on the actual content? + if @actual_content || resource.parameter(:source) + # Actual content is already set, value contains it's checksum + value + else + # The content only happens to look like a checksum by chance. + @actual_content = value.is_a?(Puppet::Pops::Types::PBinaryType::Binary) ? value.binary_buffer : value + resource.parameter(:checksum).sum(@actual_content) + end else + # Our argument is definitely not a checksum: set actual_value and return calculated checksum. @actual_content = value.is_a?(Puppet::Pops::Types::PBinaryType::Binary) ? value.binary_buffer : value resource.parameter(:checksum).sum(@actual_content) end @@ -155,17 +151,13 @@ def write(file) def each_chunk_from if actual_content.is_a?(String) yield actual_content - elsif content_is_really_a_checksum? && actual_content.nil? + elsif actual_content.nil? yield read_file_from_filebucket elsif actual_content.nil? yield '' end end - def content_is_really_a_checksum? - checksum?(should) - end - def read_file_from_filebucket dipper = resource.bucket raise "Could not get filebucket from file" unless dipper diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb index 68849d99a0..9bbd27f0ad 100644 --- a/spec/integration/type/file_spec.rb +++ b/spec/integration/type/file_spec.rb @@ -640,20 +640,6 @@ def get_aces_for_path_by_sid(path, sid) it_should_behave_like "files are backed up", {} do let(:filebucket_digest) { method(:digest) } end - - it "should give a checksum deprecation warning" do - expect(Puppet).to receive(:puppet_deprecation_warning).with('Using a checksum in a file\'s "content" property is deprecated. The ability to use a checksum to retrieve content from the filebucket using the "content" property will be removed in a future release. The literal value of the "content" property will be written to the file. The checksum retrieval functionality is being replaced by the use of static catalogs. See https://puppet.com/docs/puppet/latest/static_catalogs.html for more information.', {:file => 'my/file.pp', :line => 5}) - d = digest("this is some content") - catalog.add_resource described_class.new(:path => path, :content => "{#{digest_algorithm}}#{d}") - catalog.apply - end - - it "should not give a checksum deprecation warning when no content is specified while checksum and checksum value are used" do - expect(Puppet).not_to receive(:puppet_deprecation_warning) - d = digest("this is some content") - catalog.add_resource described_class.new(:path => path, :checksum => digest_algorithm, :checksum_value => d) - catalog.apply - end end CHECKSUM_TYPES_TO_TRY.each do |checksum_type, checksum|