Skip to content

Commit 9b8772c

Browse files
authored
Merge pull request #406 from imaqsood/MODULES-5225
fix(MODULES-5225): include app_name in cache key for virt_dir_path
2 parents 6cecc85 + 7a3cc8a commit 9b8772c

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

lib/puppet/provider/iis_virtual_directory/webadministration.rb

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def create
3030
Puppet.debug "Creating #{@resource[:name]}"
3131

3232
verify_physicalpath
33+
dir_path = virt_dir_path
3334

3435
cmd = []
3536
if local_path?(@resource[:physicalpath])
@@ -40,17 +41,17 @@ def create
4041
else
4142
# New-WebVirtualDirectory fails when PhysicalPath is a UNC path that unavailable,
4243
# and UNC paths are inherently not necessarily always available.
43-
cmd << "New-Item -Type VirtualDirectory 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' "
44+
cmd << "New-Item -Type VirtualDirectory 'IIS:\\Sites\\#{dir_path}' "
4445
end
4546
cmd << "-Application \"#{@resource[:application]}\" " if @resource[:application]
4647
cmd << "-PhysicalPath \"#{@resource[:physicalpath]}\" " if @resource[:physicalpath]
4748
cmd << '-ErrorAction Stop;'
4849
if @resource[:user_name]
49-
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' " \
50+
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{dir_path}' " \
5051
"-Name 'userName' -Value '#{@resource[:user_name]}' -ErrorAction Stop;"
5152
end
5253
if @resource[:password]
53-
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' " \
54+
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{dir_path}' " \
5455
"-Name 'password' -Value '#{escape_string(@resource[:password])}' -ErrorAction Stop;"
5556
end
5657
cmd = cmd.join
@@ -67,10 +68,10 @@ def update
6768

6869
cmd = []
6970

70-
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' -Name 'physicalPath' -Value '#{@resource[:physicalpath]}';" if @resource[:physicalpath]
71-
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' -Name 'application' -Value '#{@resource[:application]}';" if @resource[:application]
72-
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' -Name 'userName' -Value '#{@resource[:user_name]}';" if @resource[:user_name]
73-
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' -Name 'password' -Value '#{escape_string(@resource[:password])}';" if @resource[:password]
71+
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path}' -Name 'physicalPath' -Value '#{@resource[:physicalpath]}';" if @resource[:physicalpath]
72+
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path}' -Name 'application' -Value '#{@resource[:application]}';" if @resource[:application]
73+
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path}' -Name 'userName' -Value '#{@resource[:user_name]}';" if @resource[:user_name]
74+
cmd << "Set-ItemProperty -Path 'IIS:\\Sites\\#{virt_dir_path}' -Name 'password' -Value '#{escape_string(@resource[:password])}';" if @resource[:password]
7475

7576
cmd = cmd.join
7677
result = self.class.run(cmd)
@@ -79,11 +80,11 @@ def update
7980

8081
def destroy
8182
Puppet.debug "Destroying #{@resource[:name]}"
82-
test = self.class.run("Test-Path -Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}'")
83+
test = self.class.run("Test-Path -Path 'IIS:\\Sites\\#{virt_dir_path}'")
8384
if test[:stdout].strip.casecmp('true').zero?
8485
cmd = []
8586
cmd << 'Remove-Item '
86-
cmd << "-Path 'IIS:\\Sites\\#{virt_dir_path(@resource[:sitename], @resource[:name])}' "
87+
cmd << "-Path 'IIS:\\Sites\\#{virt_dir_path}' "
8788
cmd << '-Recurse '
8889
cmd << '-ErrorAction Stop '
8990
cmd = cmd.join
@@ -131,15 +132,24 @@ def self.instances
131132
end
132133
end
133134

134-
def virt_dir_path(sitename, name)
135+
def virt_dir_path
136+
sitename = @resource[:sitename]
137+
name = @resource[:name]
138+
app_name = @resource[:application] if @resource[:application]
139+
135140
@cached_virt_dir_path ||= {}
136141

137-
key = "#{sitename}/#{name}"
138-
@cached_virt_dir_path[key] ||= begin
142+
cache_key = "#{sitename}/#{name}/#{app_name}"
143+
@cached_virt_dir_path[cache_key] ||= begin
139144
parts = name.tr('/', '\\').split('\\')
140-
parts.shift if parts.first.casecmp?(sitename)
141-
normalized_name = parts.join('\\')
142-
"#{sitename}\\#{normalized_name}"
145+
parts.shift if parts.first&.casecmp?(sitename)
146+
parts.shift if app_name && parts.first&.casecmp?(app_name)
147+
148+
path_parts = [sitename]
149+
path_parts << app_name if app_name
150+
path_parts.concat(parts)
151+
152+
path_parts.join('\\')
143153
end
144154
end
145155

0 commit comments

Comments
 (0)