From c6d34847d508dd983a606e46aff54acf5eaa7938 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 6 Jan 2026 22:26:14 -0500 Subject: [PATCH] fix race condition in deploy script rename logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous version failed when /opt/jrunner existed from a prior run, because mv cannot move over an existing directory. Now the script: 1. Removes target directory if it exists 2. Removes intermediate jrunner/ directory if it exists and differs from target (prevents collision) 3. Extracts cleanly 4. Renames to target name This fixes the issue where ./deploy.sh /opt/jr_test would fail if /opt/jrunner already existed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- deploy.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/deploy.sh b/deploy.sh index f785ceb..4157dec 100755 --- a/deploy.sh +++ b/deploy.sh @@ -22,16 +22,27 @@ echo "Building jrunner..." ./gradlew build echo "Deploying to ${DEPLOY_DIR}..." + +# Remove both target and intermediate jrunner directory if they exist if [ -d "${DEPLOY_DIR}" ]; then - echo "Removing existing deployment..." + echo "Removing existing deployment at ${DEPLOY_DIR}..." sudo rm -rf "${DEPLOY_DIR}" fi -sudo mkdir -p "$(dirname "${DEPLOY_DIR}")" -sudo unzip -q jrunner/build/distributions/jrunner.zip -d "$(dirname "${DEPLOY_DIR}")" -# Rename if custom directory name was specified +PARENT_DIR="$(dirname "${DEPLOY_DIR}")" +EXTRACT_DIR="${PARENT_DIR}/jrunner" + +if [ -d "${EXTRACT_DIR}" ] && [ "${EXTRACT_DIR}" != "${DEPLOY_DIR}" ]; then + echo "Removing existing jrunner directory at ${EXTRACT_DIR}..." + sudo rm -rf "${EXTRACT_DIR}" +fi + +# Extract and rename if needed +sudo mkdir -p "${PARENT_DIR}" +sudo unzip -q jrunner/build/distributions/jrunner.zip -d "${PARENT_DIR}" + if [ "$(basename "${DEPLOY_DIR}")" != "jrunner" ]; then - sudo mv "$(dirname "${DEPLOY_DIR}")/jrunner" "${DEPLOY_DIR}" + sudo mv "${EXTRACT_DIR}" "${DEPLOY_DIR}" fi # Only create symlink for default location