@@ -40,17 +40,17 @@ def create
4040 else
4141 # New-WebVirtualDirectory fails when PhysicalPath is a UNC path that unavailable,
4242 # and UNC paths are inherently not necessarily always available.
43- cmd << "New-Item -Type VirtualDirectory 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' "
43+ cmd << "New-Item -Type VirtualDirectory 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' "
4444 end
4545 cmd << "-Application \" #{ @resource [ :application ] } \" " if @resource [ :application ]
4646 cmd << "-PhysicalPath \" #{ @resource [ :physicalpath ] } \" " if @resource [ :physicalpath ]
4747 cmd << '-ErrorAction Stop;'
4848 if @resource [ :user_name ]
49- cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' " \
49+ cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' " \
5050 "-Name 'userName' -Value '#{ @resource [ :user_name ] } ' -ErrorAction Stop;"
5151 end
5252 if @resource [ :password ]
53- cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' " \
53+ cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' " \
5454 "-Name 'password' -Value '#{ escape_string ( @resource [ :password ] ) } ' -ErrorAction Stop;"
5555 end
5656 cmd = cmd . join
@@ -67,10 +67,10 @@ def update
6767
6868 cmd = [ ]
6969
70- cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' -Name 'physicalPath' -Value '#{ @resource [ :physicalpath ] } ';" if @resource [ :physicalpath ]
71- cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' -Name 'application' -Value '#{ @resource [ :application ] } ';" if @resource [ :application ]
72- cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' -Name 'userName' -Value '#{ @resource [ :user_name ] } ';" if @resource [ :user_name ]
73- cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' -Name 'password' -Value '#{ escape_string ( @resource [ :password ] ) } ';" if @resource [ :password ]
70+ cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' -Name 'physicalPath' -Value '#{ @resource [ :physicalpath ] } ';" if @resource [ :physicalpath ]
71+ cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' -Name 'application' -Value '#{ @resource [ :application ] } ';" if @resource [ :application ]
72+ cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' -Name 'userName' -Value '#{ @resource [ :user_name ] } ';" if @resource [ :user_name ]
73+ cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' -Name 'password' -Value '#{ escape_string ( @resource [ :password ] ) } ';" if @resource [ :password ]
7474
7575 cmd = cmd . join
7676 result = self . class . run ( cmd )
@@ -79,11 +79,11 @@ def update
7979
8080 def destroy
8181 Puppet . debug "Destroying #{ @resource [ :name ] } "
82- test = self . class . run ( "Test-Path -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } '" )
82+ test = self . class . run ( "Test-Path -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } '" )
8383 if test [ :stdout ] . strip . casecmp ( 'true' ) . zero?
8484 cmd = [ ]
8585 cmd << 'Remove-Item '
86- cmd << "-Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' "
86+ cmd << "-Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resouce [ :sitename ] , @resource [ :name ] } ' "
8787 cmd << '-Recurse '
8888 cmd << '-ErrorAction Stop '
8989 cmd = cmd . join
@@ -131,6 +131,19 @@ def self.instances
131131 end
132132 end
133133
134+ def virt_dir_path ( sitename , name )
135+ @cached_virt_dir_path ||= { }
136+
137+ key = "#{ sitename } /#{ name } "
138+ @cached_virt_dir_path [ key ] ||= begin
139+ parts = name . tr ( '/' , '\\' ) . split ( '\\' )
140+ parts . shift if parts . first . casecmp? ( sitename )
141+ normalized_name = parts . join ( '\\' )
142+ site_path = "#{ sitename } \\ #{ normalized_name } "
143+ [ normalized_name , site_path ]
144+ end
145+ end
146+
134147 def escape_string ( value )
135148 value . gsub ( "'" , "''" )
136149 end
0 commit comments