From 72d6ad29030c192380d9fd63cc364f108e946bfa Mon Sep 17 00:00:00 2001 From: Commander Date: Mon, 2 Mar 2026 10:46:50 -0800 Subject: [PATCH] fix: use pushd/popd in goofys install to prevent working directory corruption The goofys build process used cd to change into a temporary directory, but on failure paths cd - could leave the working directory in a deleted temp dir instead of returning to SCRIPT_DIR. This caused discover_profiles to fail with "No profiles found" since config/profiles was resolved relative to the (now deleted) working directory. Changes: - Replace cd/cd - with pushd/popd in install_goofys to properly manage directory stack across all success and failure paths - Add cd $SCRIPT_DIR safety net at the start of select_profile as defense-in-depth against any future directory side effects Fixes #86 --- setup.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/setup.sh b/setup.sh index 53f9680c..66333f9f 100755 --- a/setup.sh +++ b/setup.sh @@ -533,12 +533,12 @@ install_goofys() { info "Building goofys from PR #778 (gopsutil v3 fix for Apple Silicon)..." local temp_dir="/tmp/goofys-build-$$" mkdir -p "$temp_dir" - cd "$temp_dir" + pushd "$temp_dir" > /dev/null if git clone -b feature/upgrade-gopsutil https://github.com/chiehting/goofys.git 2>/dev/null; then - cd goofys + pushd goofys > /dev/null if go install . 2>/dev/null; then - cd - && rm -rf "$temp_dir" + popd > /dev/null && popd > /dev/null && rm -rf "$temp_dir" # Check if build successful local goofys_path="" @@ -562,7 +562,7 @@ install_goofys() { fi fi fi - cd - && rm -rf "$temp_dir" + popd > /dev/null 2>&1; popd > /dev/null 2>&1; rm -rf "$temp_dir" warning "Build from source failed" else info "Go compiler not found, skipping source build" @@ -777,6 +777,9 @@ install_optional_tools() { select_profile() { step "Select Configuration Profile" + # Ensure we are in the script directory (guards against cd side effects from tool installs) + cd "$SCRIPT_DIR" + local profiles=($(discover_profiles)) if [ ${#profiles[@]} -eq 0 ]; then