Skip to content

Commit

Permalink
file diffs should work on Solaris too
Browse files Browse the repository at this point in the history
  • Loading branch information
marcparadise committed Jul 31, 2012
1 parent bb7c05f commit 90b988f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 9 additions & 3 deletions chef/lib/chef/provider/file.rb
Expand Up @@ -58,9 +58,15 @@ def diff_current_from_content source_content

def diff_current source_path
begin
# -N: Treat missing files as empty
# Solaris diff doesn't support -N (treat missing files as empty)
# For compatibility we'll create a temp file if the file does not exist
# and substitute it
unless ::File.exists?(source_path)
altfile = Tempfile.new('chef-tempfile')
source_path = altfile.path
end
# -u: Unified diff format
result = shell_out("diff -u -N #{@current_resource.path} #{source_path}" )
result = shell_out("diff -u #{@current_resource.path} #{source_path}" )
# diff will set a non-zero return code even when there's
# valid stdout results, if it encounters something unexpected
# So as long as we have output, we'll show it.
Expand All @@ -76,7 +82,7 @@ def diff_current source_path
rescue Exception => e
# Should *not* receive this, but in some circumstances it seems that
# an exception can be thrown even using shell_out instead of shell_out!
"Could not determine diff"
"Could not determine diff. Error: #{e.message}"
end
end

Expand Down
10 changes: 6 additions & 4 deletions chef/spec/unit/provider/file_spec.rb
Expand Up @@ -284,12 +284,14 @@
@provider.load_current_resource
result = @provider.diff_current_from_content "foo baz"
# remove the file name info which varies.
require 'pp'
pp result
result.shift(2)
result.should == ["@@ -0,0 +1 @@", "+foo baz"]
# Result appearance seems to vary slightly under solaris diff
# So we'll compare the second line which is common to both.
# Solaris: -1,1 +1,0 @@, "+foo baz"
# Linux/Mac: -1,0, +1 @@, "+foo baz"
result.length.should == 2
result[1].should == "+foo baz"
end
end
end
end

0 comments on commit 90b988f

Please sign in to comment.