Class: Puppet::Util::Lockfile Private
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.
This class provides a simple API for managing a lock file whose contents are an (optional) String. In addition to querying the basic state (#locked?) of the lock, managing the lock (#lock, #unlock), the contents can be retrieved at any time while the lock is held (#lock_data). This can be used to store pids, messages, etc.
Direct Known Subclasses
Instance Attribute Summary collapse
- #file_path ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(file_path) ⇒ Lockfile
constructor
private
A new instance of Lockfile.
-
#lock(lock_data = nil) ⇒ boolean
private
True if lock is successfully acquired, false otherwise.
-
#lock_data ⇒ String
private
Retrieve the (optional) lock data that was specified at the time the file was locked.
- #locked? ⇒ Boolean private
- #unlock ⇒ Object private
Constructor Details
#initialize(file_path) ⇒ 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.
12 13 14 |
# File 'lib/puppet/util/lockfile.rb', line 12 def initialize(file_path) @file_path = file_path end |
Instance Attribute Details
#file_path ⇒ Object (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.
10 11 12 |
# File 'lib/puppet/util/lockfile.rb', line 10 def file_path @file_path end |
Instance Method Details
#lock(lock_data = nil) ⇒ boolean
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 true if lock is successfully acquired, false otherwise.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/puppet/util/lockfile.rb', line 25 def lock(lock_data = nil) begin Puppet::FileSystem.exclusive_create(@file_path, nil) do |fd| fd.print(lock_data) end true rescue Errno::EEXIST false end end |
#lock_data ⇒ String
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.
Retrieve the (optional) lock data that was specified at the time the file
was locked.
53 54 55 |
# File 'lib/puppet/util/lockfile.rb', line 53 def lock_data return File.read(@file_path) if file_locked? end |
#locked? ⇒ Boolean
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.
45 46 47 48 |
# File 'lib/puppet/util/lockfile.rb', line 45 def locked? # delegate logic to a more explicit private method file_locked? end |
#unlock ⇒ Object
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.
36 37 38 39 40 41 42 43 |
# File 'lib/puppet/util/lockfile.rb', line 36 def unlock if locked? Puppet::FileSystem.unlink(@file_path) true else false end end |