From 87796fe41585ba6d1da6df04c33dbd3af10a18d3 Mon Sep 17 00:00:00 2001 From: garrytan Date: Mon, 26 Oct 2026 04:37:51 +0000 Subject: [PATCH] fix(capy-install): a failed launch-file write removes only its own temp file The failure path ran rm -f "$LAUNCH_FILE".tmp.*, which also deleted the temp file a concurrent installer run (two threads on one machine, same verdict path) was about to mv, so that run lost its launch file too. write_launch_file now cleans up its own $tmp and returns 1; the caller only reports. The file's comment no longer embeds the state-root path (a newline in GSTACK_STATE_ROOT could have ended the comment). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- bin/gstack-capy-install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/gstack-capy-install b/bin/gstack-capy-install index a0354a3e3..43710f0c3 100755 --- a/bin/gstack-capy-install +++ b/bin/gstack-capy-install @@ -595,7 +595,7 @@ write_launch_file() { tmp=$(umask 077 && mktemp "$LAUNCH_FILE.tmp.XXXXXX") || return 1 { echo "# gstack launch environment, written by gstack-capy-install; mode 0600." - echo "# Apply it with: . $(shq "$LAUNCH_FILE")" + echo "# Apply it with: . " echo "# Never print it or the environment: no \`export \$(...)\`, \`env\`, \`printenv\` or bare \`set\` in a tool fence." [ -n "$LAUNCH_DIR" ] && echo "case \":\$PATH:\" in *:$(shq "$LAUNCH_DIR"):*) ;; *) PATH=$(shq "$LAUNCH_DIR"):\"\$PATH\" ;; esac; export PATH" echo "export GSTACK_SESSION_KIND=unattended" @@ -603,9 +603,9 @@ write_launch_file() { echo "export GSTACK_EPHEMERAL=$(shq "${GSTACK_EPHEMERAL:-1}")" echo "export GSTACK_CAPY=1" echo "export GSTACK_INSTALL_VERDICT=$(shq "$VERDICT")" - } > "$tmp" && chmod 0600 "$tmp" && mv -f "$tmp" "$LAUNCH_FILE" + } > "$tmp" && chmod 0600 "$tmp" && mv -f "$tmp" "$LAUNCH_FILE" || { rm -f "$tmp"; return 1; } } -write_launch_file || { rm -f "$LAUNCH_FILE".tmp.* 2>/dev/null; say "could not write the launch file $LAUNCH_FILE"; LAUNCH_FILE=""; } +write_launch_file || { say "could not write the launch file $LAUNCH_FILE"; LAUNCH_FILE=""; } echo "GSTACK_LAUNCH: ${LAUNCH_DIR:+PATH=$LAUNCH_DIR:\$PATH }GSTACK_SESSION_KIND=unattended GSTACK_STATE_ROOT=$GSTACK_STATE_ROOT GSTACK_EPHEMERAL=${GSTACK_EPHEMERAL:-1} GSTACK_CAPY=1 GSTACK_INSTALL_VERDICT=$VERDICT" [ -n "$LAUNCH_DIR" ] && echo "GSTACK_LAUNCH_PATH: $LAUNCH_DIR" [ -n "$LAUNCH_FILE" ] && echo "GSTACK_LAUNCH_FILE: $LAUNCH_FILE"