Class: LockFile Private

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/lock_file.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A lock file.

Direct Known Subclasses

CaskLock, FormulaLock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ LockFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LockFile.


11
12
13
14
15
# File 'Library/Homebrew/lock_file.rb', line 11

def initialize(name)
  @name = name.to_s
  @path = HOMEBREW_LOCKS/"#{@name}.lock"
  @lockfile = nil
end

Instance Attribute Details

#pathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


9
10
11
# File 'Library/Homebrew/lock_file.rb', line 9

def path
  @path
end

Instance Method Details

#lockObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


17
18
19
20
21
22
23
# File 'Library/Homebrew/lock_file.rb', line 17

def lock
  @path.parent.mkpath
  create_lockfile
  return if @lockfile.flock(File::LOCK_EX | File::LOCK_NB)

  raise OperationInProgressError, @name
end

#unlockObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


25
26
27
28
29
30
# File 'Library/Homebrew/lock_file.rb', line 25

def unlock
  return if @lockfile.nil? || @lockfile.closed?

  @lockfile.flock(File::LOCK_UN)
  @lockfile.close
end

#with_lockObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


32
33
34
35
36
37
# File 'Library/Homebrew/lock_file.rb', line 32

def with_lock
  lock
  yield
ensure
  unlock
end