From 0ce8ecabcd3dcd0eadaaa9526ee14dc616b5aedd Mon Sep 17 00:00:00 2001 From: Allen Houchins <32207388+allenhouchins@users.noreply.github.com> Date: Sun, 31 May 2026 21:08:00 -0500 Subject: [PATCH] Support glob expansion in trash() (#46287) 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](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/46287?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) --- .../ingesters/homebrew/scripts.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ee/maintained-apps/ingesters/homebrew/scripts.go b/ee/maintained-apps/ingesters/homebrew/scripts.go index 61e9d6f953..8c905aaf48 100644 --- a/ee/maintained-apps/ingesters/homebrew/scripts.go +++ b/ee/maintained-apps/ingesters/homebrew/scripts.go @@ -680,6 +680,31 @@ const trashFunc = `trash() { fi local trash="/Users/$logged_in_user/.Trash" + + # If the target contains glob characters, expand it and move each match. + if [[ "$target_file" == *[*?[]* ]]; then + local file file_name + local matched=false + local i=0 + # compgen -G expands the (quoted) pattern itself, so paths containing + # spaces glob correctly; reading line by line keeps each match intact. + while IFS= read -r file; do + [[ -n "$file" ]] || continue + [[ -e "$file" || -L "$file" ]] || continue + matched=true + i=$((i + 1)) + file_name="$(basename "$file")" + echo "removing $file." + # The per-match counter keeps matches that share a basename from + # overwriting each other in the trash. + mv -f "$file" "$trash/${file_name}_${timestamp}_${rand}_${i}" + done < <(compgen -G "$target_file" 2>/dev/null) + if [[ "$matched" == false ]]; then + echo "$target_file doesn't exist." + fi + return + fi + local file_name="$(basename "${target_file}")" if [[ -e "$target_file" ]]; then