mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #330 from Icinga:fix/improve_remove_itemsecure
Fix: Remove-ItemSecure is not using all args and might fail on empty path The Cmdlet `Remove-ItemSecure` was not using all args and might have crashed on empty values shipped to `-Path`
This commit is contained in:
commit
45e1117c2f
2 changed files with 8 additions and 13 deletions
|
|
@ -18,6 +18,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
* [#326](https://github.com/Icinga/icinga-powershell-framework/pull/326) Fixes import for module files, by using the full path to the module now instead of the name only, as files could be placed inside a folder which is not listed inside the `$ENV:PSModulePath`
|
* [#326](https://github.com/Icinga/icinga-powershell-framework/pull/326) Fixes import for module files, by using the full path to the module now instead of the name only, as files could be placed inside a folder which is not listed inside the `$ENV:PSModulePath`
|
||||||
* [#327](https://github.com/Icinga/icinga-powershell-framework/pull/327) Fixes possible exception on first import run for certain systems
|
* [#327](https://github.com/Icinga/icinga-powershell-framework/pull/327) Fixes possible exception on first import run for certain systems
|
||||||
* [#328](https://github.com/Icinga/icinga-powershell-framework/pull/328) Fixes installer while using installation files or the installation command, which did not overwrite default values with custom values
|
* [#328](https://github.com/Icinga/icinga-powershell-framework/pull/328) Fixes installer while using installation files or the installation command, which did not overwrite default values with custom values
|
||||||
|
* [#330](https://github.com/Icinga/icinga-powershell-framework/pull/330) Fixes `Remove-ItemSecure` which was not using all args and might fail on empty path entries
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,27 +31,21 @@ function Remove-ItemSecure()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[string]$Path,
|
[string]$Path,
|
||||||
[switch]$Recurse,
|
[switch]$Recurse = $FALSE,
|
||||||
[switch]$Force
|
[switch]$Force = $FALSE
|
||||||
)
|
)
|
||||||
|
|
||||||
if ((Test-Path $Path) -eq $FALSE) {
|
if ([string]::IsNullOrEmpty($Path) -Or (Test-Path $Path) -eq $FALSE) {
|
||||||
|
Write-IcingaConsoleError 'The provided path "{0}" does not exist' -Objects $Path;
|
||||||
return $FALSE;
|
return $FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($Recurse -And $Force) {
|
Remove-Item -Path $Path -Recurse:$Recurse -Force:$Force -ErrorAction Stop;
|
||||||
Remove-Item -Path $Path -Recurse -Force;
|
|
||||||
} elseif ($Recurse -And -Not $Force) {
|
|
||||||
Remove-Item -Path $Path -Recurse;
|
|
||||||
} elseif (-Not $Recurse -And $Force) {
|
|
||||||
Remove-Item -Path $Path -Force;
|
|
||||||
} else {
|
|
||||||
Remove-Item -Path $Path;
|
|
||||||
}
|
|
||||||
return $TRUE;
|
return $TRUE;
|
||||||
} catch {
|
} catch {
|
||||||
Write-IcingaConsoleError ([string]::Format('Failed to remove items from path "{0}": {1}', $Path, $_.Exception));
|
$ExMsg = $_.Exception;
|
||||||
|
Write-IcingaConsoleError 'Failed to remove items from path "{0}". Recurse is "{1}", Force is "{2}": "{3}"' -Objects $Path, $Recurse, $Force, $ExMsg;
|
||||||
}
|
}
|
||||||
return $FALSE;
|
return $FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue