module Puppet::FileSystem

Public Class Methods

assert_path(path) click to toggle source

Asserts that the given path is of the expected type produced by pathname

@raise [ArgumentError] when path is not of the expected type

@api public

# File lib/puppet/file_system.rb, line 341
def self.assert_path(path)
  @impl.assert_path(path)
end
basename(path) click to toggle source

@return [Object] the name of the file as a opaque handle

@api public

# File lib/puppet/file_system.rb, line 73
def self.basename(path)
  @impl.basename(assert_path(path))
end
basename_string(path) click to toggle source

@return [String] the name of the file

@api public

# File lib/puppet/file_system.rb, line 81
def self.basename_string(path)
  @impl.path_string(@impl.basename(assert_path(path)))
end
binread(path) click to toggle source

@return [String] The binary contents of the file

@api public

# File lib/puppet/file_system.rb, line 149
def self.binread(path)
  @impl.binread(assert_path(path))
end
children(path) click to toggle source

@return [Array<Object>] references to all of the children of the given

directory path, excluding `.` and `..`.

@api public

# File lib/puppet/file_system.rb, line 221
def self.children(path)
  @impl.children(assert_path(path))
end
chmod(mode, path) click to toggle source

Changes permission bits on the named path to the bit pattern represented by mode.

@param mode [Integer] The mode to apply to the file if it is created @param path [String] The path to the file, can also accept [PathName]

@raise [Errno::ENOENT]: path doesn’t exist

@api public

# File lib/puppet/file_system.rb, line 376
def self.chmod(mode, path)
  @impl.chmod(mode, path)
end
compare_stream(path, stream) click to toggle source

Compares the contents of this file against the contents of a stream.

@param stream [IO] The stream to compare the contents against @return [Boolean] Whether the contents were the same

@api public

# File lib/puppet/file_system.rb, line 317
def self.compare_stream(path, stream)
  @impl.compare_stream(assert_path(path), stream)
end
dir(path) click to toggle source

@return [Object] The directory of this file as an opaque handle

@api public

# File lib/puppet/file_system.rb, line 47
def self.dir(path)
  @impl.dir(assert_path(path))
end
dir_exist?(path) click to toggle source

@return [Boolean] Does the directory of the given path exist?

# File lib/puppet/file_system.rb, line 60
def self.dir_exist?(path)
  @impl.exist?(@impl.dir(assert_path(path)))
end
dir_mkpath(path) click to toggle source

Creates all directories down to (inclusive) the dir of the given path

# File lib/puppet/file_system.rb, line 65
def self.dir_mkpath(path)
  @impl.mkpath(@impl.dir(assert_path(path)))
end
dir_string(path) click to toggle source

@return [String] The directory of this file as a String

@api public

# File lib/puppet/file_system.rb, line 55
def self.dir_string(path)
  @impl.path_string(@impl.dir(assert_path(path)))
end
directory?(path) click to toggle source

Determines if a file is a directory.

@return [Boolean] true if the given file is a directory.

@api public

# File lib/puppet/file_system.rb, line 169
def self.directory?(path)
  @impl.directory?(assert_path(path))
end
each_line(path, &block) click to toggle source

Processes each line of the file by yielding it to the given block

@api public

# File lib/puppet/file_system.rb, line 120
def self.each_line(path, &block)
  @impl.each_line(assert_path(path), &block)
end
exclusive_create(path, mode, &block) click to toggle source

Create and open a file for write only if it doesn’t exist.

@see ::open

@raise [Errno::EEXIST] path already exists.

@api public

# File lib/puppet/file_system.rb, line 362
def self.exclusive_create(path, mode, &block)
  @impl.exclusive_create(assert_path(path), mode, &block)
end
exclusive_open(path, mode, options = 'r', timeout = 300, &block) click to toggle source

Allows exclusive updates to a file to be made by excluding concurrent access using flock. This means that if the file is on a filesystem that does not support flock, this method will provide no protection.

While polling to aquire the lock the process will wait ever increasing amounts of time in order to prevent multiple processes from wasting resources.

@param path [Pathname] the path to the file to operate on @param mode [Integer] The mode to apply to the file if it is created @param options [Integer] Extra file operation mode information to use

(defaults to read-only mode)

@param timeout [Integer] Number of seconds to wait for the lock (defaults to 300) @yield The file handle, in read-write mode @return [Void] @raise [Timeout::Error] If the timeout is exceeded while waiting to acquire the lock

@api public

# File lib/puppet/file_system.rb, line 112
def self.exclusive_open(path, mode, options = 'r', timeout = 300, &block)
  @impl.exclusive_open(assert_path(path), mode, options, timeout, &block)
end
executable?(path) click to toggle source

Determines if a file is executable.

@todo Should this take into account extensions on the windows platform?

@return [Boolean] true if this file can be executed

@api public

# File lib/puppet/file_system.rb, line 190
def self.executable?(path)
  @impl.executable?(assert_path(path))
end
exist?(path) click to toggle source

Determines if a file exists by verifying that the file can be stat’d. Will follow symlinks and verify that the actual target path exists.

@return [Boolean] true if the named file exists.

@api public

# File lib/puppet/file_system.rb, line 160
def self.exist?(path)
  @impl.exist?(assert_path(path))
end
file?(path) click to toggle source

Determines if a file is a file.

@return [Boolean] true if the given file is a file.

@api public

# File lib/puppet/file_system.rb, line 178
def self.file?(path)
  @impl.file?(assert_path(path))
end
lstat(path) click to toggle source

@return [File::Stat] Same as stat, but does not follow the last symbolic link. Instead, reports on the link itself.

@api public

# File lib/puppet/file_system.rb, line 306
def self.lstat(path)
  @impl.lstat(assert_path(path))
end
mkpath(path) click to toggle source

Creates directories for all parts of the given path.

@api public

# File lib/puppet/file_system.rb, line 214
def self.mkpath(path)
  @impl.mkpath(assert_path(path))
end
open(path, mode, options, &block) click to toggle source

Opens the given path with given mode, and options and optionally yields it to the given block.

@api public

# File lib/puppet/file_system.rb, line 39
def self.open(path, mode, options, &block)
  @impl.open(assert_path(path), mode, options, &block)
end
overlay(*files) { || ... } click to toggle source

Allows overriding the filesystem for the duration of the given block. The filesystem will only contain the given file(s).

@param files [Puppet::FileSystem::MemoryFile] the files to have available

@api private

# File lib/puppet/file_system.rb, line 27
def self.overlay(*files, &block)
  old_impl = @impl
  @impl = Puppet::FileSystem::MemoryImpl.new(*files)
  yield
ensure
  @impl = old_impl
end
path_string(path) click to toggle source

Produces a string representation of the opaque path handle.

@param path [Object] a path handle produced by {pathname} @return [String] a string representation of the path

# File lib/puppet/file_system.rb, line 350
def self.path_string(path)
  @impl.path_string(path)
end
pathname(path) click to toggle source

Produces an opaque pathname “handle” object representing the given path. Different implementations of the underlying file system may use different runtime objects. The produced “handle” should be used in all other operations that take a “path”. No operation should be directly invoked on the returned opaque object

@param path [String] The string representation of the path @return [Object] An opaque path handle on which no operations should be directly performed

@api public

# File lib/puppet/file_system.rb, line 331
def self.pathname(path)
  @impl.pathname(path)
end
read(path) click to toggle source

@return [String] The contents of the file

@api public

# File lib/puppet/file_system.rb, line 128
def self.read(path)
  @impl.read(assert_path(path))
end
read_preserve_line_endings(path) click to toggle source

Read a file keeping the original line endings intact. This attempts to open files using binary mode using some encoding overrides and falling back to IO.read when none of the encodings are valid.

@return [String] The contents of the file

@api public

# File lib/puppet/file_system.rb, line 141
def self.read_preserve_line_endings(path)
  @impl.read_preserve_line_endings(assert_path(path))
end
size(path) click to toggle source

@return [Integer] the size of the file

@api public

# File lib/puppet/file_system.rb, line 89
def self.size(path)
  @impl.size(assert_path(path))
end
stat(path) click to toggle source

@return [File::Stat] object for the named file.

@api public

# File lib/puppet/file_system.rb, line 289
def self.stat(path)
  @impl.stat(assert_path(path))
end
touch(path) click to toggle source

Touches the file. On most systems this updates the mtime of the file.

@api public

# File lib/puppet/file_system.rb, line 206
def self.touch(path)
  @impl.touch(assert_path(path))
end
writable?(path) click to toggle source

@return [Boolean] Whether the file is writable by the current process

@api public

# File lib/puppet/file_system.rb, line 198
def self.writable?(path)
  @impl.writable?(assert_path(path))
end