Skip to content

Replaces find with ls #203

Open
BrianAtZetica wants to merge 2 commits into
mona-actions:mainfrom
BrianAtZetica:fix/202-deep-find
Open

Replaces find with ls #203
BrianAtZetica wants to merge 2 commits into
mona-actions:mainfrom
BrianAtZetica:fix/202-deep-find

Conversation

@BrianAtZetica

Copy link
Copy Markdown
Contributor

This ensures it doesnt recursively search a users entire directory when checking for preexisting output files. It now only looks in the current directory.
Resolves issue where access errors were reported after find tried to search system folders and where OneDrive woudl start downlaoding all users files due to being touched by find

Fixes #202

…directory when checkgin for preexisting output files. Resolves Deep Find triggers OneDrive download

Fixes mona-actions#202
@BrianAtZetica BrianAtZetica requested a review from a team as a code owner May 16, 2026 02:46
@robandpdx robandpdx requested a review from Copilot May 18, 2026 14:01
Comment thread gh-repo-stats Outdated
ERROR_CODE=$?
if [ "${ERROR_CODE}" -eq 0 ]; then
JSON_FILE_NAME="${EXISTING_JSON_CMD:2}"
EXISTING_JSON_CMD=$(ls "$ORG_NAME-all_repos-*.json" 2>/dev/null | head -1)
Comment thread gh-repo-stats
# Load the error code #
#######################
ERROR_CODE=$?
EXISTING_FILE_CMD=$(ls "$ORG_NAME-all_repos-"* 2>/dev/null | head -1)
Comment thread gh-repo-stats
# Load the error code #
#######################
ERROR_CODE=$?
EXISTING_FILE_CMD=$(ls "$ORG_NAME-repo-conflicts-"* 2>/dev/null | head -1)
Comment thread gh-repo-stats
# Need to see if there is a file that already exists #
######################################################
EXISTING_FILE_CMD=$(find . -name "$ORG_NAME-team-conflicts-*" |grep . 2>&1)
EXISTING_FILE_CMD=$(ls "$ORG_NAME-team-conflicts-"* 2>/dev/null | head -1)

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

Replaces recursive find calls used to detect pre-existing output files with non-recursive ls invocations, addressing issue #202 where find traversed the entire user directory tree (causing OneDrive to download all files and producing permission-denied errors on system folders). Also adds Debug log lines for the found/not-found cases.

Changes:

  • Replaces four find . -name ... invocations with ls patterns scoped to the current directory.
  • Switches the success check from $? (after grep .) to a -n test on the captured output.
  • Adds Debug messages for both the "found existing" and "creating new" branches.
Show a summary per file
File Description
gh-repo-stats Swaps recursive find with ls globs and adds Debug output in GenerateFiles for the JSON, CSV, repo-conflicts, and team-conflicts file lookups.

Notable findings:

  • Line 388 has the glob fully inside double quotes (ls "$ORG_NAME-all_repos-*.json"), which prevents shell expansion — this lookup will never find an existing JSON file. The other three sites correctly close the quote before *.
  • Behavior change: the new ls approach only inspects the current working directory, whereas find . previously recursed. Depending on how the script is invoked, this may stop matching legitimate pre-existing outputs.
  • Minor indentation/whitespace inconsistencies around lines 462–464 and trailing spaces after some Debug lines.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 4

Comment thread gh-repo-stats Outdated
Comment thread gh-repo-stats
# Load the error code #
#######################
ERROR_CODE=$?
EXISTING_FILE_CMD=$(ls "$ORG_NAME-all_repos-"* 2>/dev/null | head -1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm unable to resolve this concern. Switchign to ls and looking non-recursively solved my problem of an unexpected OneDrive dowload trigger. If it isnt appropriate for all users, you'll have to reject the PR. Thanks

Comment thread gh-repo-stats
Comment on lines +462 to +464
################################
# Check ls result is not empty #
################################
Comment thread gh-repo-stats
JSON_FILE_NAME="${EXISTING_JSON_CMD}"
Debug "Found existing JSON file, using: $JSON_FILE_NAME"
else
Debug "No existing JSON file found, creating: $JSON_FILE_NAME"
corrected glob pattern, which incorrectly enclosed the wildcard in quotes

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Brian Barrett <119825052+BrianAtZetica@users.noreply.github.com>
@amenocal

amenocal commented May 19, 2026

Copy link
Copy Markdown
Contributor

@BrianAtZetica Instead of switching to ls could we still use find, but instead use -maxdepth 1 so that it restricts it to the current directory ?

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.

Deep Find triggers OneDrive download

4 participants