Sha256: 89832aa1139aeebde04cf7225745077089abed7584cc5303326d3cfda0707198

Contents?: true

Size: 771 Bytes

Versions: 12

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

# Check if a file exists.
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/files/VERSION')
  dispatch :exists do
    scope_param
    required_param 'String', :filename
    return_type 'Boolean'
  end

  def exists(scope, filename)
    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

12 entries across 12 versions & 1 rubygems

Version Path
bolt-2.9.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.8.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.7.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.6.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.5.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.4.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.3.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.3.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.2.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.1.0 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.0.1 bolt-modules/file/lib/puppet/functions/file/exists.rb
bolt-2.0.0 bolt-modules/file/lib/puppet/functions/file/exists.rb