Skip to content

Commit

Permalink
Merge pull request #5770 from hlindberg/PUP-7402_trailing-slash-alias…
Browse files Browse the repository at this point in the history
…-in-file

(PUP-7402) Handle trailing slash in File resources
  • Loading branch information
thallgren committed Apr 5, 2017
2 parents 5bbe5f2 + 1062eb2 commit ae066f9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/parser/resource.rb
Expand Up @@ -190,7 +190,7 @@ def set_parameter(param, value = nil)
alias []= set_parameter

def to_hash
@parameters.reduce({}) do |result, (_, param)|
parse_title.merge(@parameters.reduce({}) do |result, (_, param)|
value = param.value
value = (:undef == value) ? nil : value

Expand All @@ -206,7 +206,7 @@ def to_hash
end
end
result
end
end)
end

# Convert this resource to a RAL resource.
Expand Down
9 changes: 8 additions & 1 deletion lib/puppet/resource.rb
Expand Up @@ -414,7 +414,9 @@ def environment=(environment)
@environment = environment
end

# Produce a simple hash of our parameters.
# Produces a hash of attribute to value mappings where the title parsed into its components
# acts as the default values overridden by any parameter values explicitly given as parameters.
#
def to_hash
parse_title.merge parameters
end
Expand Down Expand Up @@ -650,6 +652,11 @@ def extract_parameters(params)
end
end

# Produces a hash with { :key => part_of_title } for each entry in title_patterns
# for the resource type. A typical result for a title of 'example' is {:name => 'example'}.
# A resource type with a complex title to attribute mapping returns one entry in the hash
# per part.
#
def parse_title
h = {}
type = resource_type
Expand Down
16 changes: 7 additions & 9 deletions lib/puppet/resource/catalog.rb
Expand Up @@ -82,6 +82,9 @@ def add_class(*classes)
tag(*classes)
end

# Returns [typename, title] when given a String with "Type[title]".
# Returns [nil, nil] if '[' ']' not detected.
#
def title_key_for_ref( ref )
s = ref.index('[')
e = ref.rindex(']')
Expand Down Expand Up @@ -367,18 +370,13 @@ def resource(type, title = nil)
# an instance has to be created in order to construct the unique key used when
# searching for aliases, or when app_management is active and nothing is found in
# which case it is needed by the CapabilityFinder.
# PUP-4947
res = nil
# app_mgnt = Puppet[:app_management]
# if app_mgnt || !@aliases.empty?
res = Puppet::Resource.new(type, title, { :environment => @environment_instance })

# No need to build the uniqueness key unless there are aliases
result = @resource_table[[type_name, res.uniqueness_key].flatten] unless @aliases.empty?
# PUP-4947
# end
# Must check with uniqueness key because of aliases or if resource transforms title in title
# to attribute mappings.
result = @resource_table[[type_name, res.uniqueness_key].flatten]

if result.nil? # && app_mgnt
if result.nil?
resource_type = res.resource_type
if resource_type && resource_type.is_capability?
# @todo lutter 2015-03-10: this assumes that it is legal to just
Expand Down
19 changes: 19 additions & 0 deletions spec/integration/parser/compiler_spec.rb
Expand Up @@ -648,6 +648,25 @@ class a ($b=$x) { notify {test: message=>"yes ${undef == $b}" } }
end
end

context "when dealing with resources (e.g. File) that modifies its name from title" do
[['', ''],
['', '/'],
['/', ''],
['/', '/']].each do |t, r|
it "a circular reference can be compiled with endings: title='#{t}' and ref='#{r}'" do
expect {
node = Puppet::Node.new("testing")
compile_to_catalog(<<-"MANIFEST", node)
file { '/tmp/bazinga.txt#{t}':
content => 'henrik testing',
require => File['/tmp/bazinga.txt#{r}']
}
MANIFEST
}.not_to raise_error
end
end
end

context 'when working with the trusted data hash' do
context 'and have opted in to hashed_node_data' do
it 'should make $trusted available' do
Expand Down
6 changes: 2 additions & 4 deletions spec/unit/capability_spec.rb
Expand Up @@ -400,10 +400,8 @@ class { consumer: consume => Cap[one]}
ensure => directory
}
if !defined(File["${same_dir}"]) {
file { $same_dir:
ensure => directory
}
file { $same_dir:
ensure => directory
}
PUPPET

Expand Down

0 comments on commit ae066f9

Please sign in to comment.