Sha256: 42a87a81058c83263a74b10289017059c2a282ebea311cdfd2c178bf09a24358

Contents?: true

Size: 1.81 KB

Versions: 232

Compression:

Stored size: 1.81 KB

Contents

require 'puppet/util/lockfile'

# This class provides a simple API for managing a lock file
# whose contents are a serialized JSON object.  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 structured data (state messages, etc.) about
# the lock.
#
# @see Puppet::Util::Lockfile
class Puppet::Util::JsonLockfile < Puppet::Util::Lockfile
  # Lock the lockfile.  You may optionally pass a data object, which will be
  # retrievable for the duration of time during which the file is locked.
  #
  # @param [Hash] lock_data an optional Hash of data to associate with the lock.
  #   This may be used to store pids, descriptive messages, etc.  The
  #   data may be retrieved at any time while the lock is held by
  #   calling the #lock_data method. <b>NOTE</b> that the JSON serialization
  #   does NOT support Symbol objects--if you pass them in, they will be
  #   serialized as Strings, so you should plan accordingly.
  # @return [boolean] true if lock is successfully acquired, false otherwise.
  def lock(lock_data = nil)
    return false if locked?

    super(lock_data.to_pson)
  end

  # Retrieve the (optional) lock data that was specified at the time the file
  #  was locked.
  # @return [Object] the data object.  Remember that the serialization does not
  #  support Symbol objects, so if your data Object originally contained symbols,
  #  they will be converted to Strings.
  def lock_data
    return nil unless file_locked?
    file_contents = super
    return nil if file_contents.nil? or file_contents.empty?
    PSON.parse(file_contents)
  rescue PSON::ParserError => e
    Puppet.warning "Unable to read lockfile data from #{@file_path}: not in PSON"
    nil
  end

end

Version data entries

232 entries across 232 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/util/json_lockfile.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/util/json_lockfile.rb
puppet-4.10.12 lib/puppet/util/json_lockfile.rb
puppet-4.10.12-x86-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.12-x64-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.12-universal-darwin lib/puppet/util/json_lockfile.rb
puppet-4.10.11 lib/puppet/util/json_lockfile.rb
puppet-4.10.11-x86-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.11-x64-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.11-universal-darwin lib/puppet/util/json_lockfile.rb
puppet-4.10.10 lib/puppet/util/json_lockfile.rb
puppet-4.10.10-x86-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.10-x64-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.10-universal-darwin lib/puppet/util/json_lockfile.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/util/json_lockfile.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/util/json_lockfile.rb
puppet-4.10.9 lib/puppet/util/json_lockfile.rb
puppet-4.10.9-x86-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.9-x64-mingw32 lib/puppet/util/json_lockfile.rb
puppet-4.10.9-universal-darwin lib/puppet/util/json_lockfile.rb