Class: LockFile Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
A lock file to prevent multiple Homebrew processes from modifying the same path.
Direct Known Subclasses
Instance Attribute Summary collapse
- #path ⇒ Object readonly private
Instance Method Summary collapse
- #initialize(type, locked_path) ⇒ void constructor private
- #lock ⇒ Object private
- #unlock ⇒ Object private
- #with_lock ⇒ Object private
Constructor Details
#initialize(type, locked_path) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
11 12 13 14 15 16 |
# File 'lock_file.rb', line 11 def initialize(type, locked_path) @locked_path = locked_path lock_name = locked_path.basename.to_s @path = HOMEBREW_LOCKS/"#{lock_name}.#{type}.lock" @lockfile = nil end |
Instance Attribute Details
#path ⇒ Object (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
8 9 10 |
# File 'lock_file.rb', line 8 def path @path end |
Instance Method Details
#lock ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
18 19 20 21 22 23 24 |
# File 'lock_file.rb', line 18 def lock @path.parent.mkpath create_lockfile return if @lockfile.flock(File::LOCK_EX | File::LOCK_NB) raise OperationInProgressError, @locked_path end |
#unlock ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
26 27 28 29 30 31 |
# File 'lock_file.rb', line 26 def unlock return if @lockfile.nil? || @lockfile.closed? @lockfile.flock(File::LOCK_UN) @lockfile.close end |
#with_lock ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
33 34 35 36 37 38 |
# File 'lock_file.rb', line 33 def with_lock lock yield ensure unlock end |