class Puppet::FileSystem::Posix

Public Instance Methods

binread(path) click to toggle source
  # File lib/puppet/file_system/posix.rb
2 def binread(path)
3   path.binread
4 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
12 def compare_stream(path, stream)
13   open(path, 0, 'rb') do |this|
14     bsize = stream_blksize(this, stream)
15     sa = "".force_encoding('ASCII-8BIT')
16     sb = "".force_encoding('ASCII-8BIT')
17     loop do
18       this.read(bsize, sa)
19       stream.read(bsize, sb)
20       return true if sa.empty? && sb.empty?
21       break if sa != sb
22     end
23     false
24   end
25 end

Private Instance Methods

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