Skip to content

fix: add trap to clean up temp directory on unexpected exit#1

Open
AnveshKolluri wants to merge 1 commit into
mainfrom
fix/cleanup-temp-dir-on-failure
Open

fix: add trap to clean up temp directory on unexpected exit#1
AnveshKolluri wants to merge 1 commit into
mainfrom
fix/cleanup-temp-dir-on-failure

Conversation

@AnveshKolluri

Copy link
Copy Markdown
Owner

Problem

install.sh uses set -e which terminates the script on any command failure.
When this happens (e.g., download 404, network error), the temp directory
created by mktemp -d is never cleaned up — it's leaked in /tmp.

The existing rm -rf "$TMP_DIR" calls only cover manually handled error paths,
but set -e implicit exits bypass all of them.

Repro:

VERSION=v99.99.99 curl -fsSL https://gh.io/copilot-install | bash
# curl fails with 404, set -e kills script, /tmp/tmp.XXXXX left behind


Fix-
Add trap 'rm -rf "$TMP_DIR"' EXIT immediately after mktemp -d. This ensures cleanup on all exit paths. The 4 redundant manual rm
-rf "$TMP_DIR" calls are removed since the trap handles them.

install.sh uses \set -e\ which terminates the script on any command
failure. When this happens (e.g., download 404, network error), the
temp directory created by \mktemp -d\ is never cleaned up because
the manual \
m -rf\ calls only cover explicitly handled error paths.

Add a \	rap ... EXIT\ immediately after creating the temp directory
to ensure cleanup on all exit paths. This also removes the now-
redundant manual cleanup calls, simplifying the error handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures install.sh always cleans up its mktemp -d directory even when set -e causes an implicit/early exit (e.g., failed downloads).

Changes:

  • Add an EXIT trap immediately after creating TMP_DIR to remove the temp directory on all exit paths.
  • Remove now-redundant manual rm -rf "$TMP_DIR" cleanups from individual error/success branches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants