Skip to content

Commit 1037a1a

Browse files
authored
Prepend the installed tool path in the env/sys path so that it is found first with 'Get-Command' (#45)
Prepend the installation path to ensure that the tool binaries installed by this module take precedence when using `Get-Command` or executing them from a terminal, especially in environments with multiple installations.
1 parent 254e82b commit 1037a1a

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

containers-toolkit/Private/CommonToolUtilities.psm1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ function Get-InstallationFile {
252252
}
253253

254254
# Verify that both the archive and checksum files were downloaded
255-
if (-not (Test-Path $archiveFile -ErrorAction SilentlyContinue)) {
255+
if (-not (Test-Path $archiveFile)) {
256256
Throw "Archive file not found in the release assets: `'$archiveFile`""
257257
}
258-
if (-not (Test-Path $checksumFile -ErrorAction SilentlyContinue)) {
258+
if (-not (Test-Path $checksumFile)) {
259259
Throw "Checksum file not found in the release assets: `'$checksumFile`""
260260
}
261261

@@ -274,15 +274,15 @@ function Get-InstallationFile {
274274
}
275275

276276
# Remove the checksum file after verification
277-
if (Test-Path -Path $checksumFile -ErrorAction SilentlyContinue) {
277+
if (Test-Path -Path $checksumFile) {
278278
Remove-Item -Path $checksumFile -Force -ErrorAction SilentlyContinue
279279
}
280280

281281
if (-not $isValidChecksum) {
282282
Write-Error "Checksum verification failed for $archiveFile. The file will be deleted."
283283

284284
# Remove the checksum file after verification
285-
if (Test-Path -Path $archiveFile -ErrorAction SilentlyContinue) {
285+
if (Test-Path -Path $archiveFile) {
286286
Remove-Item -Path $archiveFile -Force -ErrorAction SilentlyContinue
287287
}
288288
Throw "Checksum verification failed. One or more files are corrupted."
@@ -428,11 +428,11 @@ function Test-CheckSum {
428428

429429
Write-Debug "Checksum verification...`n`tSource file: $DownloadedFile`n`tChecksum file: $ChecksumFile"
430430

431-
if (-not (Test-Path -Path $downloadedFile -ErrorAction Continue)) {
431+
if (-not (Test-Path -Path $downloadedFile)) {
432432
Throw "Couldn't find source file: `"$downloadedFile`"."
433433
}
434434

435-
if (-not (Test-Path -Path $ChecksumFile -ErrorAction Continue)) {
435+
if (-not (Test-Path -Path $ChecksumFile)) {
436436
Throw "Couldn't find checksum file: `"$ChecksumFile`"."
437437
}
438438

containers-toolkit/Private/UpdateEnvironmentPath.psm1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ function Update-EnvironmentPath {
4141
}
4242

4343
# Check if the path needs to be changed
44+
$pathFound = "$Path" -in ($parsedPathString -split ";")
4445
switch ($Action) {
4546
"Add" {
46-
$pathChanged = $parsedPathString -notlike "*$Tool*"
47+
$pathChanged = (-not $pathFound)
4748
$toAction = $Path
4849
$ActionVerb = "Adding"
4950
}
5051
"Remove" {
51-
$pathChanged = $parsedPathString -like "*$Tool*"
52+
$pathChanged = $pathFound
5253
$toAction = $Tool
5354
$ActionVerb = "Removing"
5455
}
@@ -109,11 +110,11 @@ function AddFeatureToPath ($PathString, $ToolPath) {
109110
if (!$PathString) {
110111
Throw 'Env path cannot be null or an empty string'
111112
}
112-
return "$PathString;$ToolPath"
113+
return (ParsePathString -PathString "$ToolPath;$PathString")
113114
}
114115

115116
function RemoveFeatureFromPath ($PathString, $Tool) {
116-
$pathString = ParsePathString -Path $pathString
117+
$pathString = ParsePathString -PathString $pathString
117118
$parsedString = $pathString -split ";" | Where-Object { ($_ -notlike "*$tool*") }
118119

119120
if (!$parsedString) {

0 commit comments

Comments
 (0)