def diff_current(temp_path)
suppress_resource_reporting = false
return [ "(diff output suppressed by config)" ] if Chef::Config[:diff_disabled]
return [ "(no temp file with new content, diff output suppressed)" ] unless ::File.exists?(temp_path)
target_path = if ::File.exists?(@current_resource.path)
@current_resource.path
else
suppress_resource_reporting = true
tempfile = Tempfile.new('chef-tempfile')
tempfile.path
end
diff_filesize_threshold = Chef::Config[:diff_filesize_threshold]
diff_output_threshold = Chef::Config[:diff_output_threshold]
if ::File.size(target_path) > diff_filesize_threshold || ::File.size(temp_path) > diff_filesize_threshold
return [ "(file sizes exceed #{diff_filesize_threshold} bytes, diff output suppressed)" ]
end
return [ "(current file is binary, diff output suppressed)"] if is_binary?(target_path)
return [ "(new content is binary, diff output suppressed)"] if is_binary?(temp_path)
begin
result = shell_out("diff -u #{target_path} #{temp_path}" )
rescue Exception => e
return [ "Could not determine diff. Error: #{e.message}" ]
end
if not result.stdout.empty?
if result.stdout.length > diff_output_threshold
[ "(long diff of over #{diff_output_threshold} characters, diff output suppressed)" ]
else
val = result.stdout.split("\n")
val.delete("\\ No newline at end of file")
@new_resource.diff(val.join("\\n")) unless suppress_resource_reporting
val
end
elsif not result.stderr.empty?
[ "Could not determine diff. Error: #{result.stderr}" ]
else
[ "(no diff)" ]
end
end