[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

Markus Roberts Markus at reality.com
Wed Jul 14 10:37:09 UTC 2010


The following commit has been merged in the upstream branch:
commit 94fa5d5de2ad8f9d916178bce7ff9eeba748047a
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Fri Jul 9 17:11:36 2010 -0700

    [#4182] show_diff was broken for streamed file contents
    
    show_diff was written assuming that a file's contents would be loaded
    into memory. That's no longer true, for perfomance reasons.
    This patch streams the file to a temporary file to take the
    diff.
    As a consequence, it means that when show_diff is on, files may get
    streamed twice.

diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
index 7d54164..d7bb022 100755
--- a/lib/puppet/type/file/content.rb
+++ b/lib/puppet/type/file/content.rb
@@ -1,5 +1,6 @@
 require 'net/http'
 require 'uri'
+require 'tempfile'
 
 require 'puppet/util/checksums'
 require 'puppet/network/http/api/v1'
@@ -101,7 +102,9 @@ module Puppet
             result = super
 
             if ! result and Puppet[:show_diff]
-                string_file_diff(@resource[:path], actual_content)
+                write_temporarily do |path|
+                    print diff(@resource[:path], path)
+                end
             end
             return result
         end
@@ -137,6 +140,19 @@ module Puppet
             return return_event
         end
 
+        def write_temporarily
+            tempfile = Tempfile.new("puppet-file")
+            tempfile.open
+
+            write(tempfile)
+
+            tempfile.close
+
+            yield tempfile.path
+
+            tempfile.delete
+        end
+
         def write(file)
             resource.parameter(:checksum).sum_stream { |sum|
                 each_chunk_from(actual_content || resource.parameter(:source)) { |chunk|
diff --git a/spec/unit/type/file/content_spec.rb b/spec/unit/type/file/content_spec.rb
index f1001aa..2c00e50 100755
--- a/spec/unit/type/file/content_spec.rb
+++ b/spec/unit/type/file/content_spec.rb
@@ -175,14 +175,15 @@ describe content do
 
                 it "should display a diff if the current contents are different from the desired content" do 
                     @content.should = "some content"
-                    @content.expects(:string_file_diff).once
+                    @content.expects(:diff).returns("my diff").once
+                    @content.expects(:print).with("my diff").once
 
                     @content.insync?("other content")
                 end
 
                 it "should not display a diff if the sum for the current contents is the same as the sum for the desired content" do 
                     @content.should = "some content"
-                    @content.expects(:string_file_diff).never
+                    @content.expects(:diff).never
 
                     @content.insync?("{md5}" + Digest::MD5.hexdigest("some content"))
                 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list