Skip to content

Commit

Permalink
(Docs)(DOCUMENT-1429) Update find_file() comment in files.rb
Browse files Browse the repository at this point in the history
Testing confirms that the `find_file()` function may indeed be used to
verify the existence of a file specified by absolute path, with the
caveat that this check appears to be performed prior to any resource
changes made by the same code.

The following code, when run via "puppet apply", accurately reports the
existence or non-existence of a test file *before* deleting that file.

```
$testpath = '/tmp/testfile'
file { $testpath: ensure => absent }
if find_file($testpath) {
  notify { "$testpath exists.": }
} else {
  notify { "$testpath does not exist.": }
}
```
  • Loading branch information
pillarsdotnet committed Aug 7, 2023
1 parent fc70183 commit 1d5757f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/puppet/parser/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def find_manifests_in_modules(pattern, environment)
# * modulename/filename selector: a file is found in the file directory
# of the named module.
#
# In the second case a nil is returned if there isn't a file found. In the
# first case (absolute path), there is no existence check done and so the
# path will be returned even if there isn't a file available.
# The check for file existence is performed on the node compiling the
# manifest. A node running "puppet apply" compiles its own manifest, but
# a node running "puppet agent" depends on the configured puppetserver
# for compiling. In either case, a nil is returned if no file is found.
#
# @param template [String] the file selector
# @param environment [Puppet::Node::Environment] the environment in which to search
Expand Down

0 comments on commit 1d5757f

Please sign in to comment.