summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2012-08-28 16:28:19 -0400
committerBryan McLellan <btm@loftninjas.org>2012-08-28 16:28:19 -0400
commitf86eeac96b2634a585c60e1ea010de90a7d22e1a (patch)
tree437891be0d23ee7f4eb8e56ea25dcff71d07c6e6
parent036295b9aa94d0e711a770ff72cddad76d5f5f22 (diff)
downloadchef-f86eeac96b2634a585c60e1ea010de90a7d22e1a.tar.gz
Look at our source line endings before we compare them
We may have a file on disk with CRLF line endings, if so, we need to use binmode so the file we write to disk will match. We suck at CRLF. See CHEF-2991.
-rw-r--r--chef/spec/unit/provider/cookbook_file_spec.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/chef/spec/unit/provider/cookbook_file_spec.rb b/chef/spec/unit/provider/cookbook_file_spec.rb
index 79b700347d..6df58d24a1 100644
--- a/chef/spec/unit/provider/cookbook_file_spec.rb
+++ b/chef/spec/unit/provider/cookbook_file_spec.rb
@@ -131,8 +131,6 @@ EXPECTED
describe "when the file exists but has incorrect content" do
before do
@tempfile = Tempfile.open('cookbook_file_spec')
- # Use binary mode to avoid CRLF on windows
- @tempfile.binmode
@new_resource.path(@target_file = @tempfile.path)
@tempfile.puts "the wrong content"
@tempfile.close
@@ -182,8 +180,10 @@ EXPECTED
before do
Chef::FileAccessControl.any_instance.stub(:modified?).and_return(false)
@tempfile = Tempfile.open('cookbook_file_spec')
- # Use binary mode to avoid CRLF on windows
- @tempfile.binmode
+ # CHEF-2991: We handle CRLF very poorly and we don't know what line endings
+ # our source file is going to have, so we use binary mode to preserve CRLF if needed.
+ source_file = CHEF_SPEC_DATA + "/cookbooks/apache2/files/default/apache2_module_conf_generate.pl"
+ @tempfile.binmode unless File.open(source_file, "rb") { |f| f.read =~ /\r/ }
@new_resource.path(@target_file = @tempfile.path)
@tempfile.write(@file_content)
@tempfile.close