Sha256: 4476f07658bb142081b32db0abf20aa03a6302baad46e5a8f77aa60f2c907512

Contents?: true

Size: 909 Bytes

Versions: 6

Compression:

Stored size: 909 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/files/VERSION')
  dispatch :readable do
    scope_param
    required_param 'String', :filename
    return_type 'Boolean'
  end

  def readable(scope, filename)
    Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)
    found = Puppet::Parser::Files.find_file(filename, scope.compiler.environment)
    found ? File.readable?(found) : false
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bolt-2.14.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-2.13.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-2.12.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-2.11.1 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-2.11.0 bolt-modules/file/lib/puppet/functions/file/readable.rb
bolt-2.10.0 bolt-modules/file/lib/puppet/functions/file/readable.rb