From 0c788ae0204b34bc1eb1d6c0710eeaf9c37b85df Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Sun, 10 Jan 2021 19:07:21 -0800 Subject: [PATCH 1/2] Simplify parse_encrypt by exiting early if encrypt file doesn't exist. Signed-off-by: Ross Smith II --- yadm | 81 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/yadm b/yadm index 4cae9eb..3720306 100755 --- a/yadm +++ b/yadm @@ -1871,6 +1871,12 @@ function parse_encrypt() { ENCRYPT_INCLUDE_FILES=() ENCRYPT_EXCLUDE_FILES=() + FINAL_INCLUDE=() + ENCRYPT_INCLUDE_FILES=() + + if [ ! -f "$YADM_ENCRYPT" ] ; then + return + fi cd_work "Parsing encrypt" || return @@ -1883,47 +1889,44 @@ function parse_encrypt() { shopt -s globstar &> /dev/null exclude_pattern="^!(.+)" - if [ -f "$YADM_ENCRYPT" ] ; then - # parse both included/excluded - while IFS='' read -r line || [ -n "$line" ]; do - if [[ ! $line =~ ^# && ! $line =~ ^[[:blank:]]*$ ]] ; then - local IFS=$'\n' - for pattern in $line; do - if [[ "$pattern" =~ $exclude_pattern ]]; then - for ex_file in ${BASH_REMATCH[1]}; do - if [ -e "$ex_file" ]; then - ENCRYPT_EXCLUDE_FILES+=("$ex_file") - fi - done - else - for in_file in $pattern; do - if [ -e "$in_file" ]; then - ENCRYPT_INCLUDE_FILES+=("$in_file") - fi - done - fi - done - fi - done < "$YADM_ENCRYPT" - - # remove excludes from the includes - #(SC2068 is disabled because in this case, we desire globbing) - FINAL_INCLUDE=() - #shellcheck disable=SC2068 - for included in "${ENCRYPT_INCLUDE_FILES[@]}"; do - skip= - #shellcheck disable=SC2068 - for ex_file in ${ENCRYPT_EXCLUDE_FILES[@]}; do - [ "$included" == "$ex_file" ] && { skip=1; break; } + # parse both included/excluded + while IFS='' read -r line || [ -n "$line" ]; do + if [[ ! $line =~ ^# && ! $line =~ ^[[:blank:]]*$ ]] ; then + local IFS=$'\n' + for pattern in $line; do + if [[ "$pattern" =~ $exclude_pattern ]]; then + for ex_file in ${BASH_REMATCH[1]}; do + if [ -e "$ex_file" ]; then + ENCRYPT_EXCLUDE_FILES+=("$ex_file") + fi + done + else + for in_file in $pattern; do + if [ -e "$in_file" ]; then + ENCRYPT_INCLUDE_FILES+=("$in_file") + fi + done + fi done - [ -n "$skip" ] || FINAL_INCLUDE+=("$included") - done + fi + done < "$YADM_ENCRYPT" - # sort the encrypted files - #shellcheck disable=SC2207 - IFS=$'\n' ENCRYPT_INCLUDE_FILES=($(LC_ALL=C sort <<<"${FINAL_INCLUDE[*]}")) - unset IFS - fi + # remove excludes from the includes + #(SC2068 is disabled because in this case, we desire globbing) + #shellcheck disable=SC2068 + for included in "${ENCRYPT_INCLUDE_FILES[@]}"; do + skip= + #shellcheck disable=SC2068 + for ex_file in ${ENCRYPT_EXCLUDE_FILES[@]}; do + [ "$included" == "$ex_file" ] && { skip=1; break; } + done + [ -n "$skip" ] || FINAL_INCLUDE+=("$included") + done + + # sort the encrypted files + #shellcheck disable=SC2207 + IFS=$'\n' ENCRYPT_INCLUDE_FILES=($(LC_ALL=C sort <<<"${FINAL_INCLUDE[*]}")) + unset IFS if [ "$unset_globstar" = "1" ]; then shopt -u globstar &> /dev/null From 84136a8633166c2b7413a941c24320c287cc351a Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Mon, 11 Jan 2021 17:17:11 -0800 Subject: [PATCH 2/2] Remove unneeded duplicate line --- yadm | 1 - 1 file changed, 1 deletion(-) diff --git a/yadm b/yadm index 3720306..259f240 100755 --- a/yadm +++ b/yadm @@ -1872,7 +1872,6 @@ function parse_encrypt() { ENCRYPT_INCLUDE_FILES=() ENCRYPT_EXCLUDE_FILES=() FINAL_INCLUDE=() - ENCRYPT_INCLUDE_FILES=() if [ ! -f "$YADM_ENCRYPT" ] ; then return