Skip to content

Commit

Permalink
Merge pull request puppetlabs#331 from joshcooper/ticket/2.7.x/11929-…
Browse files Browse the repository at this point in the history
…serve-files-in-binary-mode

(#11929) serve files in binary mode
  • Loading branch information
slippycheeze committed Jan 13, 2012
2 parents 2ac94f9 + e1f2f37 commit f4f4158
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/file_serving/content.rb
Expand Up @@ -35,7 +35,7 @@ def content
# This stat can raise an exception, too.
raise(ArgumentError, "Cannot read the contents of links unless following links") if stat.ftype == "symlink"

@content = ::File.read(full_path)
@content = Puppet::Util.binread(full_path)
end
@content
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/indirector/direct_file_server_spec.rb
Expand Up @@ -22,7 +22,7 @@
it "should return an instance capable of returning its content" do
FileTest.expects(:exists?).with(@filepath).returns(true)
File.stubs(:lstat).with(@filepath).returns(stub("stat", :ftype => "file"))
File.expects(:read).with(@filepath).returns("my content")
Puppet::Util.expects(:binread).with(@filepath).returns("my content")

instance = @terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}"))

Expand Down
12 changes: 6 additions & 6 deletions spec/integration/indirector/file_content/file_server_spec.rb
Expand Up @@ -24,7 +24,7 @@
modpath = File.join(path, "mod")
FileUtils.mkdir_p(File.join(modpath, "lib"))
file = File.join(modpath, "lib", "file.rb")
File.open(file, "w") { |f| f.puts "1" }
File.open(file, "wb") { |f| f.write "1\r\n" }

Puppet.settings[:modulepath] = "/no/such/file"

Expand All @@ -36,7 +36,7 @@
result.should_not be_nil
result.length.should == 2
result[1].should be_instance_of(Puppet::FileServing::Content)
result[1].content.should == "1\n"
result[1].content.should == "1\r\n"
end

it "should find file content in modules" do
Expand All @@ -47,15 +47,15 @@
modpath = File.join(path, "mymod")
FileUtils.mkdir_p(File.join(modpath, "files"))
file = File.join(modpath, "files", "myfile")
File.open(file, "w") { |f| f.puts "1" }
File.open(file, "wb") { |f| f.write "1\r\n" }

Puppet.settings[:modulepath] = path

result = Puppet::FileServing::Content.indirection.find("modules/mymod/myfile")

result.should_not be_nil
result.should be_instance_of(Puppet::FileServing::Content)
result.content.should == "1\n"
result.content.should == "1\r\n"
end

it "should find file content in files when node name expansions are used" do
Expand All @@ -67,7 +67,7 @@
Dir.mkdir(@path)
subdir = File.join(@path, "mynode")
Dir.mkdir(subdir)
File.open(File.join(subdir, "myfile"), "w") { |f| f.puts "1" }
File.open(File.join(subdir, "myfile"), "wb") { |f| f.write "1\r\n" }

# Use a real mount, so the integration is a bit deeper.
@mount1 = Puppet::FileServing::Configuration::Mount::File.new("one")
Expand All @@ -85,6 +85,6 @@

result.should_not be_nil
result.should be_instance_of(Puppet::FileServing::Content)
result.content.should == "1\n"
result.content.should == "1\r\n"
end
end
4 changes: 2 additions & 2 deletions spec/unit/file_serving/content_spec.rb
Expand Up @@ -102,13 +102,13 @@

it "should return the contents of the path if the file exists" do
File.expects(:stat).with(@path).returns stub("stat", :ftype => "file")
File.expects(:read).with(@path).returns(:mycontent)
Puppet::Util.expects(:binread).with(@path).returns(:mycontent)
@content.content.should == :mycontent
end

it "should cache the returned contents" do
File.expects(:stat).with(@path).returns stub("stat", :ftype => "file")
File.expects(:read).with(@path).returns(:mycontent)
Puppet::Util.expects(:binread).with(@path).returns(:mycontent)
@content.content

# The second run would throw a failure if the content weren't being cached.
Expand Down

0 comments on commit f4f4158

Please sign in to comment.