Sha256: 77eb7c20cef7e477c6c4b6485998709875ac9a7f6ca89b78092545d90cb52a70

Contents?: true

Size: 930 Bytes

Versions: 39

Compression:

Stored size: 930 Bytes

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', :filename
    return_type 'Boolean'
  end

  def exists(scope, filename)
    # Send Analytics Report
    Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)
    found = Puppet::Parser::Files.find_file(filename, scope.compiler.environment)
    found ? Puppet::FileSystem.exist?(found) : false
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
bolt-3.7.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.7.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.6.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.6.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.5.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.4.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.3.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.1.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.0.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-3.0.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.44.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.42.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.40.2 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.40.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.38.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.37.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.36.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.35.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.34.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.33.2 bolt-modules/file/lib/puppet/functions/file/exists.rb