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 (Integer) (defaults to: 'r')

    Extra file operation mode information to use (defaults to read-only mode)

  • timeout (Integer) (defaults to: 300)

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

Yields:

  • The file handle, in read-write mode

Returns:

  • (Void)

Raises:

  • (Timeout::Error)

    If the timeout is exceeded while waiting to acquire the lock



109
110
111
# File 'lib/puppet/file_system.rb', line 109

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