Method: Puppet::FileSystem.exclusive_open

Defined in:
lib/puppet/file_system.rb

.exclusive_open(path, mode, options = 'r', timeout = 300) { ... } ⇒ Void

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 acquire the lock the process will wait ever increasing amounts of time in order to prevent multiple processes from wasting resources.

Parameters:

  • path (Pathname)

    the path to the file to operate on

  • mode (Integer)

    The mode to apply to the file if it is created

  • options (String) (defaults to: 'r')

    Extra file operation mode information to use (defaults to read-only mode ‘r’) This is the standard mechanism Ruby uses in the IO class, and therefore encoding may be specified explicitly as fmode : encoding or fmode : “BOM|UTF-*” for example, a:ASCII or w+:UTF-8

  • timeout (Integer) (defaults to: 300)

    Number of seconds to wait for the lock (defaults to 300)

Yields:

  • The file handle, in the mode given by options, else read-write mode

Returns:

  • (Void)

Raises:

  • (Timeout::Error)

    If the timeout is exceeded while waiting to acquire the lock



122
123
124
# File 'lib/puppet/file_system.rb', line 122

def self.exclusive_open(path, mode, options = 'r', timeout = 300, &block)
  @impl.exclusive_open(assert_path(path), mode, options, timeout, &block)
end