Install Dosh binaries atomically
ci / test (push) Has been cancelled
ci / fuzz-smoke (push) Has been cancelled
ci / windows-client (push) Has been cancelled
ci / package-release (linux-x86_64, ubuntu-latest) (push) Has been cancelled
ci / package-release (macos-aarch64, macos-14) (push) Has been cancelled
ci / package-release (macos-x86_64, macos-13) (push) Has been cancelled
ci / package-release (windows-x86_64, windows-latest) (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
DuProcess
2026-07-02 18:41:02 -04:00
parent a48aa15308
commit 60387e9222
2 changed files with 38 additions and 11 deletions
+19 -5
View File
@@ -141,6 +141,20 @@ function Verify-ArchiveVersion($ExtractDir, $Url) {
} }
} }
function Install-Binary($Source, $Destination) {
$dir = Split-Path -Parent $Destination
$name = Split-Path -Leaf $Destination
$tmp = Join-Path $dir ".$name.tmp.$PID"
Copy-Item $Source $tmp -Force
try {
Move-Item $tmp $Destination -Force
}
catch {
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
throw
}
}
$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
@@ -168,9 +182,9 @@ function Install-Prebuilt {
if (-not $found) { if (-not $found) {
throw "prebuilt archive missing $bin" throw "prebuilt archive missing $bin"
} }
Copy-Item $found.FullName (Join-Path $bindir $bin) -Force Install-Binary $found.FullName (Join-Path $bindir $bin)
} }
Copy-Item (Join-Path $bindir "dosh-client.exe") (Join-Path $bindir "dosh.exe") -Force Install-Binary (Join-Path $bindir "dosh-client.exe") (Join-Path $bindir "dosh.exe")
return $true return $true
} }
catch { catch {
@@ -202,9 +216,9 @@ function Install-FromSource {
try { try {
Push-Location $src Push-Location $src
cargo build --release --bin dosh-client --bin dosh-bench cargo build --release --bin dosh-client --bin dosh-bench
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh-client.exe") -Force Install-Binary "target\release\dosh-client.exe" (Join-Path $bindir "dosh-client.exe")
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh.exe") -Force Install-Binary "target\release\dosh-client.exe" (Join-Path $bindir "dosh.exe")
Copy-Item "target\release\dosh-bench.exe" (Join-Path $bindir "dosh-bench.exe") -Force Install-Binary "target\release\dosh-bench.exe" (Join-Path $bindir "dosh-bench.exe")
} }
finally { finally {
Pop-Location Pop-Location
+19 -6
View File
@@ -226,13 +226,26 @@ find_extracted_binary() {
find "$1" -type f -name "$2" 2>/dev/null | sed -n '1p' find "$1" -type f -name "$2" 2>/dev/null | sed -n '1p'
} }
install_binary() {
src="$1"
dst="$2"
dst_dir="$(dirname "$dst")"
dst_base="$(basename "$dst")"
tmp="$dst_dir/.$dst_base.tmp.$$"
install -m 0755 "$src" "$tmp"
if ! mv -f "$tmp" "$dst"; then
rm -f "$tmp"
return 1
fi
}
install_extracted_binary() { install_extracted_binary() {
found="$(find_extracted_binary "$1" "$2")" found="$(find_extracted_binary "$1" "$2")"
if [ -z "$found" ]; then if [ -z "$found" ]; then
echo "prebuilt archive missing $2" >&2 echo "prebuilt archive missing $2" >&2
return 1 return 1
fi fi
install -m 0755 "$found" "$3" install_binary "$found" "$3"
} }
sha256_file() { sha256_file() {
@@ -329,7 +342,7 @@ try_install_prebuilt() {
install_extracted_binary "$tmpdir/extract" dosh-auth "$bindir/dosh-auth" || return 1 install_extracted_binary "$tmpdir/extract" dosh-auth "$bindir/dosh-auth" || return 1
fi fi
if found_bench="$(find_extracted_binary "$tmpdir/extract" dosh-bench)" && [ -n "$found_bench" ]; then if found_bench="$(find_extracted_binary "$tmpdir/extract" dosh-bench)" && [ -n "$found_bench" ]; then
install -m 0755 "$found_bench" "$bindir/dosh-bench" install_binary "$found_bench" "$bindir/dosh-bench"
fi fi
return 0 return 0
} }
@@ -388,14 +401,14 @@ install_from_source() {
fi fi
fi fi
install -m 0755 target/release/dosh-client "$bindir/dosh-client" install_binary target/release/dosh-client "$bindir/dosh-client"
ln -sf dosh-client "$bindir/dosh" ln -sf dosh-client "$bindir/dosh"
if [ "$role" = "server" ] || [ "$role" = "both" ]; then if [ "$role" = "server" ] || [ "$role" = "both" ]; then
install -m 0755 target/release/dosh-server "$bindir/dosh-server" install_binary target/release/dosh-server "$bindir/dosh-server"
install -m 0755 target/release/dosh-auth "$bindir/dosh-auth" install_binary target/release/dosh-auth "$bindir/dosh-auth"
fi fi
if [ -f target/release/dosh-bench ]; then if [ -f target/release/dosh-bench ]; then
install -m 0755 target/release/dosh-bench "$bindir/dosh-bench" install_binary target/release/dosh-bench "$bindir/dosh-bench"
fi fi
} }