summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-07-09 17:11:36 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 17:26:37 -0700
commit94fa5d5de2ad8f9d916178bce7ff9eeba748047a (patch)
treef35df7789d824e26f126b6cc052d04e0959f4c23 /lib/puppet
parent700970475c01f60490f6d05e7a94275ede704c37 (diff)
downloadpuppet-94fa5d5de2ad8f9d916178bce7ff9eeba748047a.tar.gz
puppet-94fa5d5de2ad8f9d916178bce7ff9eeba748047a.tar.xz
puppet-94fa5d5de2ad8f9d916178bce7ff9eeba748047a.zip
[#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.
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/type/file/content.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
index 7d541645c..d7bb022a3 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|