Skip to content

Commit 177b637

Browse files
committed
install: use EXIT trap for temp directory cleanup
Replace scattered rm -rf calls with a single EXIT trap to ensure the temp directory is always cleaned up on exit. Previously, failures in curl/wget download, tar extraction, chmod, or mkdir left temp files behind because set -e would exit before reaching manual cleanup calls. The trap fires on any exit (success or failure), so it covers all paths with one line while removing five redundant cleanup calls.
1 parent b175fd8 commit 177b637

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

install.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ echo "Downloading from: $DOWNLOAD_URL"
7575

7676
# Download and extract with error handling
7777
TMP_DIR="$(mktemp -d)"
78+
trap 'rm -rf -- "$TMP_DIR"' EXIT
7879
TMP_TARBALL="$TMP_DIR/copilot-${PLATFORM}-${ARCH}.tar.gz"
7980
if command -v curl >/dev/null 2>&1; then
8081
curl -fsSL "${CURL_AUTH[@]}" "$DOWNLOAD_URL" -o "$TMP_TARBALL"
8182
elif command -v wget >/dev/null 2>&1; then
8283
wget -qO "$TMP_TARBALL" "${WGET_AUTH[@]}" "$DOWNLOAD_URL"
8384
else
8485
echo "Error: Neither curl nor wget found. Please install one of them."
85-
rm -rf "$TMP_DIR"
8686
exit 1
8787
fi
8888

@@ -101,15 +101,13 @@ if [ "$CHECKSUMS_AVAILABLE" = true ]; then
101101
echo "✓ Checksum validated"
102102
else
103103
echo "Error: Checksum validation failed." >&2
104-
rm -rf "$TMP_DIR"
105104
exit 1
106105
fi
107106
elif command -v shasum >/dev/null 2>&1; then
108107
if (cd "$TMP_DIR" && shasum -a 256 -c --ignore-missing SHA256SUMS.txt >/dev/null 2>&1); then
109108
echo "✓ Checksum validated"
110109
else
111110
echo "Error: Checksum validation failed." >&2
112-
rm -rf "$TMP_DIR"
113111
exit 1
114112
fi
115113
else
@@ -120,7 +118,6 @@ fi
120118
# Check that the file is a valid tarball
121119
if ! tar -tzf "$TMP_TARBALL" >/dev/null 2>&1; then
122120
echo "Error: Downloaded file is not a valid tarball or is corrupted." >&2
123-
rm -rf "$TMP_DIR"
124121
exit 1
125122
fi
126123

@@ -144,7 +141,6 @@ fi
144141
tar -xz -C "$INSTALL_DIR" -f "$TMP_TARBALL"
145142
chmod +x "$INSTALL_DIR/copilot"
146143
echo "✓ GitHub Copilot CLI installed to $INSTALL_DIR/copilot"
147-
rm -rf "$TMP_DIR"
148144

149145
# Check if installed binary is accessible
150146
if ! command -v copilot >/dev/null 2>&1; then

0 commit comments

Comments
 (0)