Remove Get-Item for current application physical path to prevent errors if current path does not exist. Update comparison to use the physical path value already stored in the $application variable.
SUMMARY
When using win_iis_webapplication under certain conditions the underliying powershell code will produce an irrecoverable error. Premise: If the currently set physicalPath does not exist, the execution of the module will fail with the error Cannot find path '$path' because it does not exist.
The existing path should not be validated, as this module may be run exactly to update a webApp that is broken due to a missing/modified PhysicalPath. The only path that should be validated (and it is) is the new physical path to be set.
This PR aims to improve the way the module behaves by removing the implicit check that is induced by using Get-Item to evaluate the currently set physicalPath, which is then treated as a LiteralPath to be compared as a string with the value of the new path to be set.
With this change, the paths are still compared and only changed if they differ, but the implicit validation for the currently set path is removed, preventing the module from throwing and error when it has been modified or does no longer exist. The path to be set is already validated on Line 77
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
modules/win_iis_webapplication.ps1
ADDITIONAL INFORMATION
How to reproduce the issue:
Create a folder, point webApp to use as PhysicalPath
Delete created folder, validate that webApp is still using that deleted folder path as PhysicalPath. webApp may be broken, but the PhysicalPath is still used and returned.
Execute win_iis_webapplication to change the PhysicalPath with a new one, execution will throw error Cannot find path '$pathToDeletedFolder' because it does not exist
(Can also be validated by just running the powershell code this module uses to change the physical Path. It will fail when performing the action on Line 81)
Remove Get-Item for current application physical path to prevent errors if current path does not exist. Update comparison to use the physical path value already stored in the
$application
variable.SUMMARY
When using win_iis_webapplication under certain conditions the underliying powershell code will produce an irrecoverable error. Premise: If the currently set physicalPath does not exist, the execution of the module will fail with the error
Cannot find path '$path' because it does not exist
.The existing path should not be validated, as this module may be run exactly to update a webApp that is broken due to a missing/modified PhysicalPath. The only path that should be validated (and it is) is the new physical path to be set.
This PR aims to improve the way the module behaves by removing the implicit check that is induced by using Get-Item to evaluate the currently set physicalPath, which is then treated as a LiteralPath to be compared as a string with the value of the new path to be set.
With this change, the paths are still compared and only changed if they differ, but the implicit validation for the currently set path is removed, preventing the module from throwing and error when it has been modified or does no longer exist. The path to be set is already validated on Line 77
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
How to reproduce the issue:
win_iis_webapplication
to change the PhysicalPath with a new one, execution will throw errorCannot find path '$pathToDeletedFolder' because it does not exist