Skip to content

Support glob expansion in trash() - #46287

Merged
allenhouchins merged 3 commits into
mainfrom
allenhouchins-script-enhancement
Jun 1, 2026
Merged

Support glob expansion in trash()#46287
allenhouchins merged 3 commits into
mainfrom
allenhouchins-script-enhancement

Conversation

@allenhouchins

@allenhouchins allenhouchins commented May 27, 2026

Copy link
Copy Markdown
Member

Enhance the trash() implementation to detect glob patterns in the target path, expand them, and move each matched file into the user's .Trash with a timestamp and random suffix. If no matches are found the function logs that the pattern doesn't exist.

Summary by CodeRabbit

  • New Features
    • Trash utility now supports glob patterns (*, ?, []) to remove multiple matching files at once.
    • Each trashed item receives a unique suffix to avoid filename collisions.
    • Per-file removal messages shown; a clear notification is printed when a pattern matches no files.

Review Change Stack

Enhance the trash() implementation to detect glob patterns in the target path, expand them, and move each matched file into the user's .Trash with a timestamp and random suffix. If no matches are found the function logs that the pattern doesn't exist.
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.74%. Comparing base (e09da91) to head (19d92a0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #46287      +/-   ##
==========================================
- Coverage   66.78%   66.74%   -0.04%     
==========================================
  Files        2803     2773      -30     
  Lines      223565   222726     -839     
  Branches    11345    11047     -298     
==========================================
- Hits       149309   148662     -647     
+ Misses      60693    60501     -192     
  Partials    13563    13563              
Flag Coverage Δ
backend 68.51% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@allenhouchins
allenhouchins marked this pull request as ready for review May 27, 2026 21:10
@allenhouchins
allenhouchins requested a review from a team as a code owner May 27, 2026 21:10
Copilot AI review requested due to automatic review settings May 27, 2026 21:10
fleet-release
fleet-release previously approved these changes May 27, 2026

@claude claude Bot 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Homebrew uninstall script generator’s trash() helper to recognize glob patterns in the target path, expand them, and move matched files into the logged-in user’s ~/.Trash using a timestamped name.

Changes:

  • Detect glob metacharacters in target_file and iterate over expanded matches.
  • Move each match to ~/.Trash and log a message when no matches exist.

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

Comment thread ee/maintained-apps/ingesters/homebrew/scripts.go Outdated
Comment thread ee/maintained-apps/ingesters/homebrew/scripts.go Outdated
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2964194b-0d78-4044-8a2e-8d0c8e5fb431

📥 Commits

Reviewing files that changed from the base of the PR and between b0897fd and 31cd4f5.

📒 Files selected for processing (1)
  • ee/maintained-apps/ingesters/homebrew/scripts.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • ee/maintained-apps/ingesters/homebrew/scripts.go

Walkthrough

The PR extends the embedded trash() shell function to detect glob characters in target paths. If present, it expands the pattern with compgen -G, iterates matched paths, skips missing entries, and moves each match into ~/.Trash with a unique basename suffixed by timestamp, rand, and an index while logging each removal. If no matches are found it logs that the target doesn't exist and returns. Non-glob targets retain the original single-path behavior.

Possibly related PRs

  • fleetdm/fleet#45603: Both PRs extend the trash() helper to expand and iterate over glob-pattern targets, moving each matched path into Trash with unique suffixes instead of handling a single path.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks required sections from the template including changes files, testing checklist items, and database migration checks. Most template checklist items are incomplete. Complete the PR description by addressing required template sections: add a changes file, specify testing approach, and fill out database migration and fleetd compatibility sections as applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Support glob expansion in trash()' directly and concisely describes the main enhancement being made to the trash() function.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch allenhouchins-script-enhancement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ee/maintained-apps/ingesters/homebrew/scripts.go (1)

674-675: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Per-match destination names are not unique and can overwrite files.

timestamp and rand are computed once, so multiple matches with the same basename can collide at the same Trash path (mv -f will overwrite). Generate uniqueness per file move.

Suggested fix
-  local timestamp="$(date +%Y-%m-%d-%s)"
-  local rand="$(jot -r 1 0 99999)"
+  local timestamp="$(date +%Y-%m-%d-%s)"

@@
-      local file_name="$(basename "$f")"
+      local file_name="$(basename "$f")"
+      local rand="$(jot -r 1 0 99999)"
       echo "removing $f."
       mv -f "$f" "$trash/${file_name}_${timestamp}_${rand}"

Also applies to: 692-695

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ee/maintained-apps/ingesters/homebrew/scripts.go` around lines 674 - 675, The
per-match destination name uses shared `timestamp` and `rand` variables so
multiple moves can collide and `mv -f` may overwrite; change the logic so
`timestamp` and/or `rand` (or a unique id like `$(date +%s%N)` or `mktemp` UUID)
are generated inside the per-file handling block right before performing the `mv
-f` to the Trash path, ensuring each move computes a fresh unique suffix for the
destination name (update both the occurrences where `timestamp`/`rand` are used,
e.g., the block around the variables `timestamp` and `rand` and the later moves
at the other occurrence).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ee/maintained-apps/ingesters/homebrew/scripts.go`:
- Around line 687-690: The for-loop over $target_file is subject to
word-splitting before globbing which breaks paths with spaces (variable:
target_file, loop: for f in $target_file); change the loop so the glob is
expanded as a single pattern rather than split words — for example, replace the
current loop with a safe expansion using eval (e.g. eval "for f in $target_file;
do ...; done") or explicitly expand into an array via a null-delimited expansion
before iterating, ensuring you reference target_file and the for f loop so
globbing occurs correctly for paths containing spaces.

---

Outside diff comments:
In `@ee/maintained-apps/ingesters/homebrew/scripts.go`:
- Around line 674-675: The per-match destination name uses shared `timestamp`
and `rand` variables so multiple moves can collide and `mv -f` may overwrite;
change the logic so `timestamp` and/or `rand` (or a unique id like `$(date
+%s%N)` or `mktemp` UUID) are generated inside the per-file handling block right
before performing the `mv -f` to the Trash path, ensuring each move computes a
fresh unique suffix for the destination name (update both the occurrences where
`timestamp`/`rand` are used, e.g., the block around the variables `timestamp`
and `rand` and the later moves at the other occurrence).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f54a4d7e-56a9-4fbd-8da2-786e75cf44ee

📥 Commits

Reviewing files that changed from the base of the PR and between 36eace6 and b0897fd.

📒 Files selected for processing (1)
  • ee/maintained-apps/ingesters/homebrew/scripts.go

Comment thread ee/maintained-apps/ingesters/homebrew/scripts.go Outdated
Fix glob expansion and safe handling in trash(): use compgen -G piped into a read -r loop so paths with spaces are preserved, add checks for existing files or symlinks, and introduce a per-match counter to avoid basename collisions when moving files to the trash. Also declare local variables and provide clearer comments explaining the approach and rationale.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

CI Feedback 🧐

A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

Action: aggregate-result

Failed stage: Check for failures [❌]

Failed test name: main-mysql8.0.44, integration-mdm-mysql8.0.44

Failure summary:

The action failed in the status-aggregation step because one or more test jobs reported fail in
their downloaded status artifacts.
- ./main-mysql8.0.44-status/status contained fail → marked as
failed test main-mysql8.0.44
- ./integration-mdm-mysql8.0.44-status/status contained fail → marked
as failed test integration-mdm-mysql8.0.44
The script then exited with code 1 at the check if [[ -n
"$failed_tests" ]]; then ... exit 1, causing the workflow to fail.

Relevant error logs:
1:  ##[group]Runner Image Provisioner
2:  Hosted Compute Agent
...

119:  Artifact download completed successfully.
120:  Extracting artifact entry: /home/runner/work/fleet/fleet/fast-status/status
121:  Artifact download completed successfully.
122:  Extracting artifact entry: /home/runner/work/fleet/fleet/integration-enterprise-mysql8.0.44-status/status
123:  Artifact download completed successfully.
124:  Extracting artifact entry: /home/runner/work/fleet/fleet/service-mysql8.0.44-status/status
125:  Artifact download completed successfully.
126:  Extracting artifact entry: /home/runner/work/fleet/fleet/mysql-mysql8.0.44-status/status
127:  Artifact download completed successfully.
128:  Extracting artifact entry: /home/runner/work/fleet/fleet/integration-mdm-mysql8.0.44-status/status
129:  Artifact download completed successfully.
130:  Extracting artifact entry: /home/runner/work/fleet/fleet/main-mysql8.0.44-status/status
131:  Artifact download completed successfully.
132:  Total of 10 artifact(s) downloaded
133:  Download artifact has finished successfully
134:  ##[group]Run failed_tests=""
135:  �[36;1mfailed_tests=""�[0m
136:  �[36;1mstatus_count=0�[0m
137:  �[36;1m# Find all status files (they are in directories like 'fleetctl-mysql8.0.44-status/status')�[0m
138:  �[36;1mfor status_file in $(find ./ -type f -name 'status'); do�[0m
139:  �[36;1m  status_count=$((status_count + 1))�[0m
140:  �[36;1m  # Extract test name from parent directory (e.g., 'fleetctl-mysql8.0.44-status')�[0m
141:  �[36;1m  test_dir=$(basename $(dirname "$status_file"))�[0m
142:  �[36;1m  # Remove '-status' suffix to get the test name�[0m
143:  �[36;1m  test_name="${test_dir%-status}"�[0m
144:  �[36;1m  status_content=$(cat "$status_file")�[0m
145:  �[36;1m  echo "Processing: $status_file (Test: $test_name) with status content: $status_content"�[0m
146:  �[36;1m  if grep -q "fail" "$status_file"; then�[0m
147:  �[36;1m    echo "  ❌ Test failed: $test_name"�[0m
148:  �[36;1m    failed_tests="${failed_tests}${test_name}, "�[0m
149:  �[36;1m  else�[0m
150:  �[36;1m    echo "  ✅ Test passed: $test_name"�[0m
151:  �[36;1m  fi�[0m
152:  �[36;1mdone�[0m
153:  �[36;1mif [[ $status_count -eq 0 ]]; then�[0m
154:  �[36;1m  echo "❌ ERROR: No status files found! This indicates a workflow issue."�[0m
155:  �[36;1m  exit 1�[0m
156:  �[36;1mfi�[0m
157:  �[36;1mif [[ -n "$failed_tests" ]]; then�[0m
158:  �[36;1m  echo "❌ One or more test jobs failed: ${failed_tests%, }"�[0m
159:  �[36;1m  exit 1�[0m
160:  �[36;1mfi�[0m
161:  �[36;1mecho "✅ All test jobs succeeded."�[0m
162:  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
163:  ##[endgroup]
164:  Processing: ./integration-core-mysql8.0.44-status/status (Test: integration-core-mysql8.0.44) with status content: success
165:  ✅ Test passed: integration-core-mysql8.0.44
166:  Processing: ./vuln-mysql8.0.44-status/status (Test: vuln-mysql8.0.44) with status content: success
167:  ✅ Test passed: vuln-mysql8.0.44
168:  Processing: ./service-mysql8.0.44-status/status (Test: service-mysql8.0.44) with status content: success
169:  ✅ Test passed: service-mysql8.0.44
170:  Processing: ./main-mysql8.0.44-status/status (Test: main-mysql8.0.44) with status content: fail
171:  ❌ Test failed: main-mysql8.0.44
172:  Processing: ./fleetctl-mysql8.0.44-status/status (Test: fleetctl-mysql8.0.44) with status content: success
173:  ✅ Test passed: fleetctl-mysql8.0.44
174:  Processing: ./integration-enterprise-mysql8.0.44-status/status (Test: integration-enterprise-mysql8.0.44) with status content: success
175:  ✅ Test passed: integration-enterprise-mysql8.0.44
176:  Processing: ./fast-status/status (Test: fast) with status content: success
177:  ✅ Test passed: fast
178:  Processing: ./mysql-mysql8.0.44-status/status (Test: mysql-mysql8.0.44) with status content: success
179:  ✅ Test passed: mysql-mysql8.0.44
180:  Processing: ./integration-mdm-mysql8.0.44-status/status (Test: integration-mdm-mysql8.0.44) with status content: fail
181:  ❌ Test failed: integration-mdm-mysql8.0.44
182:  Processing: ./scripts-status/status (Test: scripts) with status content: success
183:  ✅ Test passed: scripts
184:  ❌ One or more test jobs failed: main-mysql8.0.44, integration-mdm-mysql8.0.44
185:  ##[error]Process completed with exit code 1.
186:  Post job cleanup.

@allenhouchins
allenhouchins merged commit 0ce8eca into main Jun 1, 2026
38 of 41 checks passed
@allenhouchins
allenhouchins deleted the allenhouchins-script-enhancement branch June 1, 2026 02:08
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.

4 participants