@@ -166,6 +166,44 @@ def full_modulepath
166166 # @api private
167167 attr_reader :lock
168168
169+ # For use with versioned dirs
170+ # our environment path may contain symlinks, while we want to resolve the
171+ # path while reading the manifests we may want to report the resources as
172+ # coming from the configured path.
173+ attr_accessor :configured_path
174+
175+ # See :configured_path above
176+ attr_accessor :resolved_path
177+
178+ # Ensure the path given is of the format we want in the catalog/report.
179+ #
180+ # Intended for use with versioned symlinked environments. If this
181+ # environment is configured with "/etc/puppetlabs/code/environments/production"
182+ # but the resolved path is
183+ #
184+ # "/opt/puppetlabs/server/puppetserver/filesync/client/puppet-code/production_abcdef1234"
185+ #
186+ # this changes the filepath
187+ #
188+ # "/opt/puppetlabs/server/puppetserver/filesync/client/puppet-code/production_abcdef1234/modules/foo/manifests/init.pp"
189+ #
190+ # to
191+ #
192+ # "/etc/puppetlabs/code/environments/production/modules/foo/manifests/init.pp"
193+ def externalize_path ( filepath )
194+ paths_set = configured_path && resolved_path
195+ munging_possible = paths_set && configured_path != resolved_path
196+ munging_desired = munging_possible &&
197+ Puppet [ :report_configured_environmentpath ] &&
198+ filepath . to_s . start_with? ( resolved_path )
199+
200+ if munging_desired
201+ File . join ( configured_path , filepath . delete_prefix ( resolved_path ) )
202+ else
203+ filepath
204+ end
205+ end
206+
169207 # Checks to make sure that this environment did not have a manifest set in
170208 # its original environment.conf if Puppet is configured with
171209 # +disable_per_environment_manifest+ set true. If it did, the environment's
0 commit comments