Class: Puppet::FileSystem::Posix Private

Inherits:
FileImpl show all
Defined in:
lib/puppet/file_system/posix.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

JRuby, Windows

Instance Method Summary collapse

Methods inherited from FileImpl

#assert_path, #basename, #children, #chmod, #dir, #directory?, #each_line, #exclusive_create, #exclusive_open, #executable?, #exist?, #expand_path, #file?, #lstat, #mkpath, #open, #path_string, #pathname, #read, #read_preserve_line_endings, #readlink, #replace_file, #size, #stat, #symlink, #symlink?, #touch, #unlink, #writable?

Instance Method Details

#binread(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


2
3
4
# File 'lib/puppet/file_system/posix.rb', line 2

def binread(path)
  path.binread
end

#compare_stream(path, stream) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet/file_system/posix.rb', line 12

def compare_stream(path, stream)
  open(path, 0, 'rb') do |this|
    bsize = stream_blksize(this, stream)
    sa = "".force_encoding('ASCII-8BIT')
    sb = "".force_encoding('ASCII-8BIT')
    loop do
      this.read(bsize, sa)
      stream.read(bsize, sb)
      return true if sa.empty? && sb.empty?
      break if sa != sb
    end
    false
  end
end