Sha256: 616d3ebb212f38e5b256e01e9c59ad20d295a87147c2093252fe5161b660766b

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

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

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

    future = executor&.future || Puppet.lookup(:future) { {} }
    fallback = future.fetch('file_paths', false)

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bolt-3.17.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.16.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.16.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.15.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.14.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.13.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.12.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.11.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.10.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.9.2 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.9.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.9.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.8.1 bolt-modules/file/lib/puppet/functions/file/exists.rb