@@ -304,17 +304,32 @@ def resources_missing_from_catalog(resources_to_check)
304304 unless res =~ /\A ([\w :]+)\[ (.+)\] \z /
305305 raise ArgumentError , "Resource #{ res } is not in the expected format"
306306 end
307- resource ( type : Regexp . last_match ( 1 ) , title : Regexp . last_match ( 2 ) ) . nil?
307+
308+ type = Regexp . last_match ( 1 )
309+ title = normalized_title ( Regexp . last_match ( 2 ) , type )
310+ resource ( type : type , title : title ) . nil?
308311 end
309312 end
310313
314+ # Private method: Given a title string, normalize it according to the rules
315+ # used by puppet 4.10.x for file resource title normalization:
316+ # https://github.com/puppetlabs/puppet/blob/4.10.x/lib/puppet/type/file.rb#L42
317+ def normalized_title ( title_string , type )
318+ return title_string if type != 'File'
319+
320+ matches = title_string . match ( %r{^(?<normalized_path>/|.+:/|.*[^/])/*\Z }m )
321+ matches [ :normalized_path ] || title_string
322+ end
323+
311324 # Private method: Build the resource hash to be used used for O(1) lookups by type and title.
312325 # This method is called the first time the resource hash is accessed.
313326 def build_resource_hash
314327 @resource_hash = { }
315328 resources . each do |resource |
316329 @resource_hash [ resource [ 'type' ] ] ||= { }
317- @resource_hash [ resource [ 'type' ] ] [ resource [ 'title' ] ] = resource
330+
331+ title = normalized_title ( resource [ 'title' ] , resource [ 'type' ] )
332+ @resource_hash [ resource [ 'type' ] ] [ title ] = resource
318333
319334 if resource . key? ( 'parameters' ) && resource [ 'parameters' ] . key? ( 'alias' )
320335 @resource_hash [ resource [ 'type' ] ] [ resource [ 'parameters' ] [ 'alias' ] ] = resource
0 commit comments