From 8dbeab8dac6c2528c2a39c85954f1cb141fa4b27 Mon Sep 17 00:00:00 2001 From: Reinier Criel Date: Mon, 13 Apr 2026 13:45:20 -0700 Subject: [PATCH] Address code quality --- install-scripts/uninstall-safe-chain.ps1 | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/install-scripts/uninstall-safe-chain.ps1 b/install-scripts/uninstall-safe-chain.ps1 index fea98f2..1304247 100644 --- a/install-scripts/uninstall-safe-chain.ps1 +++ b/install-scripts/uninstall-safe-chain.ps1 @@ -57,14 +57,28 @@ function Get-SafeChainCommand { return Get-Command safe-chain -ErrorAction SilentlyContinue | Select-Object -First 1 } -function Get-ReportedInstallDir { +function Get-ValidatedSafeChainCommandPath { $command = Get-SafeChainCommand - if (-not $command) { + if (-not $command -or [string]::IsNullOrWhiteSpace($command.Path)) { + return $null + } + + $installDir = Get-InstallDirFromBinaryPath -BinaryPath $command.Path + if (-not $installDir) { + return $null + } + + return $command.Path +} + +function Get-ReportedInstallDir { + $safeChainPath = Get-ValidatedSafeChainCommandPath + if (-not $safeChainPath) { return $null } try { - $reportedInstallDir = & safe-chain get-install-dir 2>$null | Select-Object -First 1 + $reportedInstallDir = & $safeChainPath get-install-dir 2>$null | Select-Object -First 1 if ($reportedInstallDir) { $reportedInstallDir = $reportedInstallDir.Trim() } @@ -110,12 +124,7 @@ function Find-SafeChainBinary { return $safeChainBin } - $command = Get-SafeChainCommand - if ($command) { - return $command.Source - } - - return $null + return Get-ValidatedSafeChainCommandPath } function Invoke-SafeChainTeardown {