Sha256: 3c2fdc15dee23e8671bea034de802fef614e925b2c35936a5e899b00cee59194

Contents?: true

Size: 998 Bytes

Versions: 18

Compression:

Stored size: 998 Bytes

Contents

# frozen_string_literal: true

# Check if a local file is readable using Puppet's
# `Puppet::Parser::Files.find_file()` function. This will only check files on the
# machine you run Bolt on.
Puppet::Functions.create_function(:'file::readable', Puppet::Functions::InternalFunction) do
  # @param filename Absolute path or Puppet file path.
  # @return Whether the file is readable.
  # @example Check a file on disk
  #   file::readable('/tmp/i_dumped_this_here')
  # @example check a file from the modulepath
  #   file::readable('example/VERSION')
  dispatch :readable do
    scope_param
    required_param 'String[1]', :filename
    return_type 'Boolean'
  end

  def readable(scope, filename)
    # Send Analytics Report
    executor = Puppet.lookup(:bolt_executor) {}
    executor&.report_function_call(self.class.name)

    # Find the file path if it exists, otherwise return nil
    found = Bolt::Util.find_file_from_scope(filename, scope)
    found ? File.readable?(found) : false
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
bolt-4.0.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.29.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.28.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.27.4 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.27.2 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.27.1 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.26.2 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.26.1 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.25.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.24.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.23.1 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.23.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.22.1 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.22.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.21.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.20.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.19.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-3.18.0 bolt-modules/file/lib/puppet/functions/file/readable.rb