-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add trap cleanup for all mktemp temp files (t135.9) #801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,12 +61,14 @@ install_deps() { | |
| if command_exists jq; then | ||
| local tmp | ||
| tmp=$(mktemp) | ||
| trap 'rm -f "$tmp"' RETURN | ||
| jq '. + {"type": "module"}' "$TOOL_DIR/package.json" > "$tmp" && mv "$tmp" "$TOOL_DIR/package.json" | ||
| rm -f "$tmp" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| else | ||
| # Fallback: write "type": "module" into package.json without jq | ||
| local tmp | ||
| tmp=$(mktemp) | ||
| trap 'rm -f "$tmp"' RETURN | ||
| printf '{\n "type": "module",\n' > "$tmp" | ||
| # Append everything after the opening brace | ||
| tail -n +2 "$TOOL_DIR/package.json" >> "$tmp" && mv "$tmp" "$TOOL_DIR/package.json" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,7 @@ cmd_install() { | |
| local latest_url="https://github.com/getsops/sops/releases/latest/download/sops_3.9.4_${arch}.deb" | ||
| local tmp_deb | ||
| tmp_deb=$(mktemp /tmp/sops-XXXXXX.deb) | ||
| trap 'rm -f "$tmp_deb"' RETURN | ||
| curl -fsSL "$latest_url" -o "$tmp_deb" | ||
| sudo dpkg -i "$tmp_deb" | ||
| rm -f "$tmp_deb" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3365,6 +3365,7 @@ check_model_health() { | |
| else | ||
| local probe_pid probe_tmpfile | ||
| probe_tmpfile=$(mktemp) | ||
| trap 'rm -f "$probe_tmpfile"' RETURN | ||
| ("${probe_cmd[@]}" > "$probe_tmpfile" 2>&1) & | ||
|
Comment on lines
3367
to
3369
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid leaking RETURN traps (can break These ✅ Suggested pattern (chain + restore the previous RETURN trap)- probe_tmpfile=$(mktemp)
- trap 'rm -f "$probe_tmpfile"' RETURN
+ local _prev_return_trap
+ _prev_return_trap=$(trap -p RETURN)
+ probe_tmpfile=$(mktemp)
+ trap 'rm -f "$probe_tmpfile"; eval "$_prev_return_trap"' RETURN
@@
- probe_result=$(cat "$probe_tmpfile" 2>/dev/null || true)
- rm -f "$probe_tmpfile"
+ probe_result=$(cat "$probe_tmpfile" 2>/dev/null || true)
+ rm -f "$probe_tmpfile"
+ eval "$_prev_return_trap"Also applies to: 3397-3399, 4374-4376, 7412-7414, 7947-7949 🤖 Prompt for AI Agents |
||
| probe_pid=$! | ||
| local waited=0 | ||
|
|
@@ -3394,6 +3395,7 @@ check_model_health() { | |
| else | ||
| local probe_pid probe_tmpfile | ||
| probe_tmpfile=$(mktemp) | ||
| trap 'rm -f "$probe_tmpfile"' RETURN | ||
| ("${probe_cmd[@]}" > "$probe_tmpfile" 2>&1) & | ||
| probe_pid=$! | ||
| local waited=0 | ||
|
|
@@ -4370,6 +4372,7 @@ extract_log_metadata() { | |
| # Only the final lines contain actual execution status/errors. | ||
| local log_tail_file | ||
| log_tail_file=$(mktemp) | ||
| trap 'rm -f "$log_tail_file"' RETURN | ||
| tail -20 "$log_file" > "$log_tail_file" 2>/dev/null || true | ||
|
|
||
| local rate_limit_count=0 auth_error_count=0 conflict_count=0 timeout_count=0 oom_count=0 | ||
|
|
@@ -7407,6 +7410,7 @@ populate_verify_queue() { | |
| # Insert before the end marker | ||
| local temp_file | ||
| temp_file=$(mktemp) | ||
| trap 'rm -f "$temp_file"' RETURN | ||
| awk -v entry="$entry" ' | ||
| /<!-- VERIFY-QUEUE-END -->/ { | ||
| print entry | ||
|
|
@@ -7942,6 +7946,7 @@ generate_verify_entry() { | |
| # Insert before marker using temp file (portable across macOS/Linux) | ||
| local tmp_file | ||
| tmp_file=$(mktemp) | ||
| trap 'rm -f "$tmp_file"' RETURN | ||
| awk -v entry="$full_entry" -v mark="$marker" '{ | ||
| if (index($0, mark) > 0) { print entry; } | ||
| print; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit
rm -f "$tmp_file"is now redundant. Thetrapyou've added on line 439 will handle the cleanup of the temporary file automatically when theregister_skillfunction exits, regardless of success or failure. You can safely remove this line.