summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-03-01 16:04:36 -0800
committerMatt Robinson <matt@puppetlabs.com>2011-03-02 10:45:48 -0800
commitb907ba3156cdc273e220a1fc00deb500843d19e5 (patch)
tree85210eaf9643229c2333866c70c5f68eafae1cd1 /lib
parente5cfac3cb90cbea688afdef4943d4f9dd49d8058 (diff)
downloadpuppet-b907ba3156cdc273e220a1fc00deb500843d19e5.tar.gz
puppet-b907ba3156cdc273e220a1fc00deb500843d19e5.tar.xz
puppet-b907ba3156cdc273e220a1fc00deb500843d19e5.zip
(#6541) Fix content with checksum truncation bug
The patch for #6107 fd73874147a1aaa3a047f904a0bc1ae67780a2e4 introduced a bug when content was an invalid checksum. Rather than error the checksum was invalid, it would overwrite the file with empty string, essentially truncating it. The problem with #6107 is that when I wrote it, I didn't realize that the content parameter was munged to be nil when it was a checksum, and then chunking method special cased nil content to mean you should check the filebucket. #6107 intended to fix the case where content REALLY WAS nil, and handle that by returning an empty string. This patch fixes it so that we check to see if we really passed in a checksum when chunking, and only then going to the filebucket. Surprisingly it is possible to have a content checksum should value set from source, so we have to be careful not to assume the use of the filebucket whenever there's a checksum. The following manifest produces this situation: file { "/tmp/mydir" : source => '/tmp/sourcedir', recurse => true, } I've said it before, and sure I'll say it again, but long term the file provider really needs a refactor. I'll write some acceptance tests for file behavior right after committing this so that the refactoring will be easier. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/type/file/content.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
index 5223ee333..827183213 100755
--- a/lib/puppet/type/file/content.rb
+++ b/lib/puppet/type/file/content.rb
@@ -163,13 +163,15 @@ module Puppet
Puppet.settings[:name] == "apply"
end
+ # the content is munged so if it's a checksum source_or_content is nil
+ # unless the checksum indirectly comes from source
def each_chunk_from(source_or_content)
if source_or_content.is_a?(String)
yield source_or_content
- elsif source_or_content.nil? && resource.parameter(:ensure) && [:present, :file].include?(resource.parameter(:ensure).value)
- yield ''
- elsif source_or_content.nil?
+ elsif content_is_really_a_checksum? && source_or_content.nil?
yield read_file_from_filebucket
+ elsif source_or_content.nil?
+ yield ''
elsif self.class.standalone?
yield source_or_content.content
elsif source_or_content.local?
@@ -181,6 +183,10 @@ module Puppet
private
+ def content_is_really_a_checksum?
+ checksum?(should)
+ end
+
def chunk_file_from_disk(source_or_content)
File.open(source_or_content.full_path, "r") do |src|
while chunk = src.read(8192)