@@ -40,17 +40,17 @@ def create
40
40
else
41
41
# New-WebVirtualDirectory fails when PhysicalPath is a UNC path that unavailable,
42
42
# 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 ( @resource [ :sitename ] , @resource [ :name ] ) } ' "
44
44
end
45
45
cmd << "-Application \" #{ @resource [ :application ] } \" " if @resource [ :application ]
46
46
cmd << "-PhysicalPath \" #{ @resource [ :physicalpath ] } \" " if @resource [ :physicalpath ]
47
47
cmd << '-ErrorAction Stop;'
48
48
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 ( @resource [ :sitename ] , @resource [ :name ] ) } ' " \
50
50
"-Name 'userName' -Value '#{ @resource [ :user_name ] } ' -ErrorAction Stop;"
51
51
end
52
52
if @resource [ :password ]
53
- cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' " \
53
+ cmd << "Set-ItemProperty -Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resource [ :sitename ] , @resource [ :name ] ) } ' " \
54
54
"-Name 'password' -Value '#{ escape_string ( @resource [ :password ] ) } ' -ErrorAction Stop;"
55
55
end
56
56
cmd = cmd . join
@@ -67,10 +67,10 @@ def update
67
67
68
68
cmd = [ ]
69
69
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 ( @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 ]
74
74
75
75
cmd = cmd . join
76
76
result = self . class . run ( cmd )
@@ -79,11 +79,11 @@ def update
79
79
80
80
def destroy
81
81
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 ( @resource [ :sitename ] , @resource [ :name ] ) } '" )
83
83
if test [ :stdout ] . strip . casecmp ( 'true' ) . zero?
84
84
cmd = [ ]
85
85
cmd << 'Remove-Item '
86
- cmd << "-Path 'IIS:\\ Sites\\ #{ @resource [ :sitename ] } \\ #{ @resource [ :name ] } ' "
86
+ cmd << "-Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resource [ :sitename ] , @resource [ :name ] ) } ' "
87
87
cmd << '-Recurse '
88
88
cmd << '-ErrorAction Stop '
89
89
cmd = cmd . join
@@ -131,6 +131,18 @@ def self.instances
131
131
end
132
132
end
133
133
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
+ "#{ sitename } \\ #{ normalized_name } "
143
+ end
144
+ end
145
+
134
146
def escape_string ( value )
135
147
value . gsub ( "'" , "''" )
136
148
end
0 commit comments