class Puppet::FileSystem::Posix

Public Instance Methods

binread(path) click to toggle source
  # File lib/puppet/file_system/posix.rb
3 def binread(path)
4   path.binread
5 end
compare_stream(path, stream) click to toggle source

Provide an encoding agnostic version of compare_stream

The FileUtils implementation in Ruby 2.0+ was modified in a manner where it cannot properly compare File and StringIO instances. To sidestep that issue this method reimplements the faster 2.0 version that will correctly compare binary File and StringIO streams.

   # File lib/puppet/file_system/posix.rb
13 def compare_stream(path, stream)
14   open(path, 0, 'rb') do |this|
15     bsize = stream_blksize(this, stream)
16     sa = String.new.force_encoding('ASCII-8BIT')
17     sb = String.new.force_encoding('ASCII-8BIT')
18     loop do
19       this.read(bsize, sa)
20       stream.read(bsize, sb)
21       return true if sa.empty? && sb.empty?
22       break if sa != sb
23     end
24     false
25   end
26 end

Private Instance Methods

blksize(st) click to toggle source
   # File lib/puppet/file_system/posix.rb
38 def blksize(st)
39   s = st.blksize
40   return nil unless s
41   return nil if s == 0
42   s
43 end
default_blksize() click to toggle source
   # File lib/puppet/file_system/posix.rb
45 def default_blksize
46   1024
47 end
stream_blksize(*streams) click to toggle source
   # File lib/puppet/file_system/posix.rb
29 def stream_blksize(*streams)
30   streams.each do |s|
31     next unless s.respond_to?(:stat)
32     size = blksize(s.stat)
33     return size if size
34   end
35   default_blksize()
36 end