From 01f0605055e81d47d2036119a198640933cadeb2 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Fri, 6 Oct 2023 22:25:00 -0700 Subject: [PATCH] improve chk_tree and trailblank The chk_tree will check for files in distlist that would otherwise be ignored by trailblank or that are used, by convention, as tempory / test files. Fixed a shellcheck nit in trailblank. --- chk_tree | 28 +++++++++++++++++++++++++++- trailblank | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/chk_tree b/chk_tree index 1888678..b81666c 100755 --- a/chk_tree +++ b/chk_tree @@ -260,6 +260,9 @@ fi # We ignore .*.swp files as they are a result of vim sessions. # We ignore *.out files as they are used to collect information. # We ignore single letter files as they are used for temporary files. +# We ignore files containing the any of the following in any letter case: +# +# foo bar baz curds whey rmme # declare -a FINDFILE mapfile -t FINDFILE < <(find . -type f \ @@ -267,7 +270,9 @@ mapfile -t FINDFILE < <(find . -type f \ ! -path './.git/*' ! -name .git \ ! -path './.github/*' ! -name .github \ ! -name 'CODE_OF_CONDUCT.md' ! -name 'CONTRIBUTING.md' ! -name '.gitignore' ! -name 'SECURITY.md' \ - ! -name '*.swp' ! -name '*.out' ! -name '?' | + ! -name '*.swp' ! -name '?' ! -iname '*.out*' \ + ! -iname '*foo*' ! -iname '*bar*' ! -iname '*baz*' \ + ! -iname '*curds*' ! -iname '*whey*' ! -iname '*rmmee' -print | sed -e 's/^\.\///' | sort -u) if [[ ${#FINDFILE[@]} -le 0 ]]; then echo "$0: ERROR: find file is empty" 1>&2 @@ -316,6 +321,27 @@ if [[ ${#UNKNOWN_FILE[@]} -ne 0 ]]; then echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 fi +# Look for a find in distlist that would otherwise be ignored +# +# We ignore for trailblank and FINDFILE, filenames with a single letter, and files +# that end in .out, and files containing the any of the following +# in any letter case: +# +# foo bar baz curds whey rmme +# +# So we will object is any distlist file is one of these ignored filenames. +# +INVALID_DISTLIST=$(printf '%s\n' "${DISTLIST[@]}" | \ + tr '[:upper:]' '[:lower:]' | \ + sed -n -e '/^.$/p' -e '/.*foo.*/p' -e '/.*bar.*/p' -e '/.*baz.*/p' \ + -e '/.*curds.*/p' -e '/.*whey.*/p' -e '/.*rmme.*/p' | + tr '\n' ' ') +if [[ -n $INVALID_DISTLIST ]]; then + echo "$0: ERROR: distlist contains invalid filename(s): $INVALID_DISTLIST" 1>&2 + EXIT_CODE=28 + echo "$0: Warning: set EXIT_CODE: $EXIT_CODE" 1>&2 +fi + # All Done!!! -- Jessica Noll, Age 2 # if [[ $EXIT_CODE -ne 0 ]]; then diff --git a/trailblank b/trailblank index 61fe68d..e27fb8c 100755 --- a/trailblank +++ b/trailblank @@ -212,7 +212,7 @@ if [[ -n $BACKUP_MAKEILES ]]; then echo echo "# You need execute the following to remove backup Makefiles:" echo - echo "$BACKUP_MAKEILES" | while read file; do + echo "$BACKUP_MAKEILES" | while read -r file; do echo "rm -f $file" done EXIT_CODE=7