Abstract implementation of the Puppet::FileSystem
# 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
# File lib/puppet/file_system/file_impl.rb, line 33 def basename(path) path.basename.to_s end
# File lib/puppet/file_system/file_impl.rb, line 82 def binread(path) raise NotImplementedError end
# File lib/puppet/file_system/file_impl.rb, line 114 def children(path) path.children end
# File lib/puppet/file_system/file_impl.rb, line 146 def chmod(mode, path) FileUtils.chmod(mode, path) end
# 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
# File lib/puppet/file_system/file_impl.rb, line 29 def dir(path) path.dirname end
# File lib/puppet/file_system/file_impl.rb, line 90 def directory?(path) ::File.directory?(path) end
# 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
# 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
# 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
# File lib/puppet/file_system/file_impl.rb, line 98 def executable?(path) ::File.executable?(path) end
# File lib/puppet/file_system/file_impl.rb, line 86 def exist?(path) ::File.exist?(path) end
# File lib/puppet/file_system/file_impl.rb, line 94 def file?(path) ::File.file?(path) end
# File lib/puppet/file_system/file_impl.rb, line 138 def lstat(path) File.lstat(path) end
# File lib/puppet/file_system/file_impl.rb, line 110 def mkpath(path) path.mkpath end
# File lib/puppet/file_system/file_impl.rb, line 25 def open(path, mode, options, &block) ::File.open(path, options, mode, &block) end
# File lib/puppet/file_system/file_impl.rb, line 21 def path_string(path) path.to_s end
# File lib/puppet/file_system/file_impl.rb, line 5 def pathname(path) path.is_a?(Pathname) ? path : Pathname.new(path) end
# File lib/puppet/file_system/file_impl.rb, line 74 def read(path) path.read end
# File lib/puppet/file_system/file_impl.rb, line 78 def read_preserve_line_endings(path) read(path) end
# File lib/puppet/file_system/file_impl.rb, line 126 def readlink(path) File.readlink(path) end
# File lib/puppet/file_system/file_impl.rb, line 37 def size(path) path.size end
# File lib/puppet/file_system/file_impl.rb, line 134 def stat(path) File.stat(path) end
# File lib/puppet/file_system/file_impl.rb, line 118 def symlink(path, dest, options = {}) FileUtils.symlink(path, dest, options) end
# File lib/puppet/file_system/file_impl.rb, line 122 def symlink?(path) File.symlink?(path) end
# File lib/puppet/file_system/file_impl.rb, line 106 def touch(path) ::FileUtils.touch(path) end
# File lib/puppet/file_system/file_impl.rb, line 130 def unlink(*paths) File.unlink(*paths) end
# File lib/puppet/file_system/file_impl.rb, line 102 def writable?(path) path.writable? end