class Puppet::FileSystem::FileImpl

Abstract implementation of the Puppet::FileSystem

Public Instance Methods

assert_path(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 9
def assert_path(path)
  return path if path.is_a?(Pathname)

  # Some paths are string, or in the case of WatchedFile, it pretends to be
  # one by implementing to_str.
  if path.respond_to?(:to_str)
    Pathname.new(path)
  else
    raise ArgumentError, "FileSystem implementation expected Pathname, got: '#{path.class}'"
  end
end
basename(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 33
def basename(path)
  path.basename.to_s
end
binread(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 82
def binread(path)
  raise NotImplementedError
end
children(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 114
def children(path)
  path.children
end
chmod(mode, path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 146
def chmod(mode, path)
  FileUtils.chmod(mode, path)
end
compare_stream(path, stream) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 142
def compare_stream(path, stream)
  open(path, 0, 'rb') { |this| FileUtils.compare_stream(this, stream) }
end
dir(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 29
def dir(path)
  path.dirname
end
directory?(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 90
def directory?(path)
  ::File.directory?(path)
end
each_line(path) { |line| ... } click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 66
def each_line(path, &block)
  ::File.open(path) do |f|
    f.each_line do |line|
      yield line
    end
  end
end
exclusive_create(path, mode, &block) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 41
def exclusive_create(path, mode, &block)
  opt = File::CREAT | File::EXCL | File::WRONLY
  self.open(path, mode, opt, &block)
end
exclusive_open(path, mode, options = 'r', timeout = 300) { |rf| ... } click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 46
def exclusive_open(path, mode, options = 'r', timeout = 300, &block)
  wait = 0.001 + (Kernel.rand / 1000)
  written = false
  while !written
    ::File.open(path, options, mode) do |rf|
      if rf.flock(::File::LOCK_EX|::File::LOCK_NB)
        yield rf
        written = true
      else
        sleep wait
        timeout -= wait
        wait *= 2
        if timeout < 0
          raise Timeout::Error, "Timeout waiting for exclusive lock on #{@path}"
        end
      end
    end
  end
end
executable?(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 98
def executable?(path)
  ::File.executable?(path)
end
exist?(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 86
def exist?(path)
  ::File.exist?(path)
end
file?(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 94
def file?(path)
  ::File.file?(path)
end
lstat(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 138
def lstat(path)
  File.lstat(path)
end
mkpath(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 110
def mkpath(path)
  path.mkpath
end
open(path, mode, options, &block) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 25
def open(path, mode, options, &block)
  ::File.open(path, options, mode, &block)
end
path_string(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 21
def path_string(path)
  path.to_s
end
pathname(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 5
def pathname(path)
  path.is_a?(Pathname) ? path : Pathname.new(path)
end
read(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 74
def read(path)
  path.read
end
read_preserve_line_endings(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 78
def read_preserve_line_endings(path)
  read(path)
end
size(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 37
def size(path)
  path.size
end
stat(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 134
def stat(path)
  File.stat(path)
end
touch(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 106
def touch(path)
  ::FileUtils.touch(path)
end
writable?(path) click to toggle source
# File lib/puppet/file_system/file_impl.rb, line 102
def writable?(path)
  path.writable?
end