Prevent glob expansion from corrupting file discovery#3
Open
pascal-zarrad wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Improves log file discovery for the container’s logrotate config generation by preventing shell glob expansion issues and adding E2E coverage to ensure only intended files are matched.
Changes:
- Refactors
logrotate-create-config.shto buildfindfilters via a Bash array and consume results with-print0/read -d ''. - Adds E2E tests validating extension filtering, rotated-file exclusion, and glob-expansion immunity.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| logrotate.d/logrotate-create-config.sh | Builds find predicates as an array and switches discovery to -print0/NUL-safe reads. |
| e2e/tests/02_file_discovery.sh | Adds end-to-end scenarios for file ending filtering, rotated-name exclusion, and glob-expansion regression coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+28
to
+51
| find_filter=() | ||
| for ending in $logs_ending; do | ||
| if [ ${#find_filter[@]} -gt 0 ]; then | ||
| find_filter+=("-o") | ||
| fi | ||
| let COUNTER=COUNTER+1 | ||
| find_filter+=("-iname" "*.${ending}") | ||
| done | ||
| IFS=$SAVEIFS | ||
|
|
||
| # Check if regex search is enabled | ||
| if [ -n "${LOGS_FILE_REGEX}" ]; then | ||
| if [ "$COUNTER" -eq "0" ]; then | ||
| LOGS_FILE_ENDINGS_INSTRUCTION="-regex $LOGS_FILE_REGEX" | ||
| else | ||
| LOGS_FILE_ENDINGS_INSTRUCTION="$LOGS_FILE_ENDINGS_INSTRUCTION -o -regex $LOGS_FILE_REGEX" | ||
| if [ ${#find_filter[@]} -gt 0 ]; then | ||
| find_filter+=("-o") | ||
| fi | ||
| find_filter+=("-regex" "${LOGS_FILE_REGEX}") | ||
| fi | ||
|
|
||
| for d in ${log_dirs} | ||
| do | ||
| log_files=$(find ${d} -type f $LOGS_FILE_ENDINGS_INSTRUCTION) || continue | ||
| for f in ${log_files}; | ||
| do | ||
| if [ -f "${f}" ]; then | ||
| echo "Found new file $f, Processing..." | ||
| handleSingleFile "$f" | ||
| fi | ||
| done | ||
| for d in ${log_dirs}; do | ||
| if [ ! -d "${d}" ]; then | ||
| continue | ||
| fi | ||
|
|
||
| while IFS= read -r -d '' f; do | ||
| echo "Found new file $f, Processing..." | ||
| handleSingleFile "$f" | ||
| done < <(find "${d}" -type f \( "${find_filter[@]}" \) -print0 2>/dev/null) |
Use bash array for find arguments instead of building a string. The unquoted glob pattern *.log was subject to shell expansion when .log files existed in the container CWD, causing find to discover all files regardless of LOG_FILE_ENDINGS setting.
pascal-zarrad
force-pushed
the
feature/log-file-endings
branch
from
March 14, 2026 23:41
6a97970 to
599b8f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request improves the reliability and correctness of log file discovery in the log rotation system, especially regarding how files are matched by their endings and how the script handles potential shell globbing issues. It also adds new end-to-end tests to verify these behaviors.
Log file discovery improvements:
logrotate-create-config.shto build thefindcommand filter as an array, preventing shell glob expansion issues and ensuring only files with the correct endings are matched. Also switched to using-print0withread -r -d ''for robust filename handling.Testing enhancements:
02_file_discovery.shto verify:access.log-20251021) are not matched..logfiles present in the container's current working directory, preventing issues caused by glob expansion.Solves #1