From 8ab173465817ce168b41b347f90823811d6ea998 Mon Sep 17 00:00:00 2001 From: David Zurow Date: Wed, 22 Apr 2026 04:40:04 -0400 Subject: [PATCH] Improve stale entry cleanup for cross-platform compatibility Enhanced stale entry cleanup to support both Windows and Bash process lookups. --- scripts/discover-servers.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/discover-servers.sh b/scripts/discover-servers.sh index 3547a0c..17437f4 100755 --- a/scripts/discover-servers.sh +++ b/scripts/discover-servers.sh @@ -22,10 +22,19 @@ for f in "$servers_dir"/*.json; do pid=$(jq -r '.pid' "$f" 2>/dev/null) || continue - # Clean up stale entries - if ! kill -0 "$pid" 2>/dev/null; then - rm -f "$f" - continue + # Clean up stale entries. Under MSYS/Cygwin, accept either a Windows-native + # process lookup or `kill -0` so we handle both Windows and Bash-owned PIDs. + if [[ "$OSTYPE" == msys* || "$OSTYPE" == cygwin* ]]; then + if ! powershell.exe -NoProfile -Command "Get-Process -Id $pid -ErrorAction SilentlyContinue | Out-Null; if (\$?) { exit 0 } else { exit 1 }" \ + && ! kill -0 "$pid" 2>/dev/null; then + rm -f "$f" + continue + fi + else + if ! kill -0 "$pid" 2>/dev/null; then + rm -f "$f" + continue + fi fi entry=$(jq '.' "$f" 2>/dev/null) || continue