Make Windows PATH install idempotent
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
This commit is contained in:
+21
-4
@@ -299,6 +299,26 @@ function Assert-SafeUpdateCache($Path) {
|
|||||||
$full
|
$full
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Add-UserPath($PathToAdd) {
|
||||||
|
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
|
$entries = @()
|
||||||
|
if ($userPath) {
|
||||||
|
$entries = @($userPath -split ';' | Where-Object { $_ })
|
||||||
|
}
|
||||||
|
$wanted = Normalize-PathForCompare $PathToAdd
|
||||||
|
foreach ($entry in $entries) {
|
||||||
|
if ((Normalize-PathForCompare $entry) -ieq $wanted) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$next = if ($entries.Count -gt 0) {
|
||||||
|
(@($entries) + $PathToAdd) -join ';'
|
||||||
|
} else {
|
||||||
|
$PathToAdd
|
||||||
|
}
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", $next, "User")
|
||||||
|
}
|
||||||
|
|
||||||
$bindir = Join-Path $Prefix "bin"
|
$bindir = Join-Path $Prefix "bin"
|
||||||
$configDir = Join-Path $HOME ".config\dosh"
|
$configDir = Join-Path $HOME ".config\dosh"
|
||||||
New-Item -ItemType Directory -Force -Path $bindir, $configDir | Out-Null
|
New-Item -ItemType Directory -Force -Path $bindir, $configDir | Out-Null
|
||||||
@@ -447,10 +467,7 @@ predict = true
|
|||||||
"@ | Set-Content -NoNewline -Encoding utf8 $hostsConfig
|
"@ | Set-Content -NoNewline -Encoding utf8 $hostsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
Add-UserPath $bindir
|
||||||
if (-not (($userPath -split ';') -contains $bindir)) {
|
|
||||||
[Environment]::SetEnvironmentVariable("Path", "$userPath;$bindir", "User")
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Installed Dosh client to $bindir"
|
Write-Host "Installed Dosh client to $bindir"
|
||||||
Write-Host "Configured UDP port $Port"
|
Write-Host "Configured UDP port $Port"
|
||||||
|
|||||||
@@ -145,6 +145,20 @@ fn windows_installer_reuses_persistent_source_update_cache() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn windows_installer_adds_user_path_idempotently() {
|
||||||
|
let ps1 = include_str!("../install.ps1");
|
||||||
|
assert!(ps1.contains("function Add-UserPath($PathToAdd)"));
|
||||||
|
assert!(ps1.contains("$wanted = Normalize-PathForCompare $PathToAdd"));
|
||||||
|
assert!(ps1.contains("-ieq $wanted"));
|
||||||
|
assert!(ps1.contains("(@($entries) + $PathToAdd) -join ';'"));
|
||||||
|
assert!(
|
||||||
|
!ps1.contains("\"$userPath;$bindir\""),
|
||||||
|
"Windows installer must not write a leading semicolon when user PATH is empty"
|
||||||
|
);
|
||||||
|
assert!(ps1.contains("Add-UserPath $bindir"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unix_installer_rejects_unsafe_source_update_cache_paths() {
|
fn unix_installer_rejects_unsafe_source_update_cache_paths() {
|
||||||
let install = include_str!("../install.sh");
|
let install = include_str!("../install.sh");
|
||||||
|
|||||||
Reference in New Issue
Block a user