@@ -30,6 +30,7 @@ def create
30
30
Puppet . debug "Creating #{ @resource [ :name ] } "
31
31
32
32
verify_physicalpath
33
+ dir_path = virt_dir_path
33
34
34
35
cmd = [ ]
35
36
if local_path? ( @resource [ :physicalpath ] )
@@ -40,17 +41,17 @@ def create
40
41
else
41
42
# New-WebVirtualDirectory fails when PhysicalPath is a UNC path that unavailable,
42
43
# 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 } ' "
44
45
end
45
46
cmd << "-Application \" #{ @resource [ :application ] } \" " if @resource [ :application ]
46
47
cmd << "-PhysicalPath \" #{ @resource [ :physicalpath ] } \" " if @resource [ :physicalpath ]
47
48
cmd << '-ErrorAction Stop;'
48
49
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 } ' " \
50
51
"-Name 'userName' -Value '#{ @resource [ :user_name ] } ' -ErrorAction Stop;"
51
52
end
52
53
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 } ' " \
54
55
"-Name 'password' -Value '#{ escape_string ( @resource [ :password ] ) } ' -ErrorAction Stop;"
55
56
end
56
57
cmd = cmd . join
@@ -67,10 +68,10 @@ def update
67
68
68
69
cmd = [ ]
69
70
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 ]
74
75
75
76
cmd = cmd . join
76
77
result = self . class . run ( cmd )
@@ -79,11 +80,11 @@ def update
79
80
80
81
def destroy
81
82
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 } '" )
83
84
if test [ :stdout ] . strip . casecmp ( 'true' ) . zero?
84
85
cmd = [ ]
85
86
cmd << 'Remove-Item '
86
- cmd << "-Path 'IIS:\\ Sites\\ #{ virt_dir_path ( @resource [ :sitename ] , @resource [ :name ] ) } ' "
87
+ cmd << "-Path 'IIS:\\ Sites\\ #{ virt_dir_path } ' "
87
88
cmd << '-Recurse '
88
89
cmd << '-ErrorAction Stop '
89
90
cmd = cmd . join
@@ -131,15 +132,24 @@ def self.instances
131
132
end
132
133
end
133
134
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
+
135
140
@cached_virt_dir_path ||= { }
136
141
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
139
144
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 ( '\\' )
143
153
end
144
154
end
145
155
0 commit comments