From 3da74e4226c9732b06ccf49866fc0ed7d2d8f319 Mon Sep 17 00:00:00 2001 From: Bob Vincent Date: Wed, 26 Jul 2023 11:25:33 -0400 Subject: [PATCH] (Docs)(DOCUMENT-1429) Update find_file() comment in files.rb 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.": } } ``` --- lib/puppet/parser/files.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb index 30187ca7f8b..5460a0db9c9 100644 --- a/lib/puppet/parser/files.rb +++ b/lib/puppet/parser/files.rb @@ -29,9 +29,11 @@ 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. + # If this function is called from "puppet agent", the check for file + # existence is performed on the Puppet Primary server. If called from + # "puppet apply", the check is performed on the local host. In both cases, + # the check is performed before any resources are changed, and 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