Skip to content

Commit f093e22

Browse files
committed
Fixes unintended PS path change
1 parent 2341085 commit f093e22

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1313

1414
### Bugfixes
1515

16+
* [#578](https://github.com/Icinga/icinga-powershell-framework/issues/578) Fixes installation and uninstallation commands changing PowerShell location even when not necessary
1617
* [#582](https://github.com/Icinga/icinga-powershell-framework/issues/582) Fixes background service registration caused by migration task for v1.10.0 being executed even when no services were defined before
1718
* [#588](https://github.com/Icinga/icinga-powershell-framework/issues/588) Fixes threshold values causing an error because of too aggressive regex expression
1819
* [#599](https://github.com/Icinga/icinga-powershell-plugins/issues/599) Fixes plugin argument parser to proceed with real argument names and possible provided aliases

lib/core/dev/Write-IcingaForWindowsComponentCompilationFile.psm1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function Write-IcingaForWindowsComponentCompilationFile()
55
[string]$CompiledFilePath = ''
66
);
77

8+
# Store our current shell location
9+
[string]$OldLocation = Get-Location;
810
# Get the current location and leave this folder
911
Set-Location -Path $ScriptRootPath;
1012
Set-Location -Path '..';
@@ -57,4 +59,7 @@ function Write-IcingaForWindowsComponentCompilationFile()
5759

5860
Import-Module -Name $ModulePath -Force;
5961
Import-Module -Name $ModulePath -Force -Global;
62+
63+
# Set our location back to the previous folder
64+
Set-Location -Path $OldLocation;
6065
}

lib/core/framework/Uninstall-IcingaForWindows.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Uninstall-IcingaForWindows()
4545
}
4646
}
4747

48-
Set-Location -Path (Get-IcingaForWindowsRootPath);
48+
Set-IcingaPSLocation;
4949

5050
Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows from this host';
5151
Write-IcingaConsoleNotice 'Uninstalling Icinga Security configuration if applied';

lib/core/repository/Uninstall-IcingaComponent.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ function Uninstall-IcingaComponent()
2828
}
2929

3030
# Set our current location to the PowerShell modules folder, to prevent possible folder lock during uninstallation
31-
Set-Location (Get-IcingaForWindowsRootPath);
31+
Set-IcingaPSLocation -Path $UninstallPath;
3232

3333
Write-IcingaConsoleNotice -Message 'Uninstalling Icinga for Windows component "{0}" from "{1}"' -Objects $UninstallComponent, $UninstallPath;
3434
if (Remove-ItemSecure -Path $UninstallPath -Recurse -Force) {
3535
Write-IcingaConsoleNotice -Message 'Successfully removed Icinga for Windows component "{0}" from "{1}"' -Objects $UninstallComponent, $UninstallPath;
3636
if ($UninstallComponent -ne 'icinga-powershell-framework') {
3737
Remove-Module $UninstallComponent -Force -ErrorAction SilentlyContinue;
3838
# In case we are not removing the framework itself, set the location to the Icinga for Windows Folder
39-
Set-Location (Get-IcingaFrameworkRootPath);
39+
Set-IcingaPSLocation -Path $UninstallPath;
4040
}
4141
return $TRUE;
4242
} else {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function Set-IcingaPSLocation()
2+
{
3+
param (
4+
[string]$Path = (Get-Location)
5+
);
6+
7+
if ([string]::IsNullOrEmpty($Path)) {
8+
return;
9+
}
10+
11+
if ((Test-Path $Path) -eq $FALSE) {
12+
return;
13+
}
14+
15+
[string]$IfWRootPath = Get-IcingaForWindowsRootPath;
16+
[string]$CurrentPath = Get-Location;
17+
18+
if ($CurrentPath -Like ([string]::Format('{0}*', $Path))) {
19+
Set-Location -Path $IfWRootPath;
20+
}
21+
}

0 commit comments

Comments
 (0)