Simplify parse_encrypt by exiting early
if encrypt file doesn't exist. Signed-off-by: Ross Smith II <ross@smithii.com>
This commit is contained in:
parent
a5b1067e02
commit
0c788ae020
1 changed files with 42 additions and 39 deletions
81
yadm
81
yadm
|
@ -1871,6 +1871,12 @@ function parse_encrypt() {
|
||||||
|
|
||||||
ENCRYPT_INCLUDE_FILES=()
|
ENCRYPT_INCLUDE_FILES=()
|
||||||
ENCRYPT_EXCLUDE_FILES=()
|
ENCRYPT_EXCLUDE_FILES=()
|
||||||
|
FINAL_INCLUDE=()
|
||||||
|
ENCRYPT_INCLUDE_FILES=()
|
||||||
|
|
||||||
|
if [ ! -f "$YADM_ENCRYPT" ] ; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
cd_work "Parsing encrypt" || return
|
cd_work "Parsing encrypt" || return
|
||||||
|
|
||||||
|
@ -1883,47 +1889,44 @@ function parse_encrypt() {
|
||||||
shopt -s globstar &> /dev/null
|
shopt -s globstar &> /dev/null
|
||||||
|
|
||||||
exclude_pattern="^!(.+)"
|
exclude_pattern="^!(.+)"
|
||||||
if [ -f "$YADM_ENCRYPT" ] ; then
|
# parse both included/excluded
|
||||||
# parse both included/excluded
|
while IFS='' read -r line || [ -n "$line" ]; do
|
||||||
while IFS='' read -r line || [ -n "$line" ]; do
|
if [[ ! $line =~ ^# && ! $line =~ ^[[:blank:]]*$ ]] ; then
|
||||||
if [[ ! $line =~ ^# && ! $line =~ ^[[:blank:]]*$ ]] ; then
|
local IFS=$'\n'
|
||||||
local IFS=$'\n'
|
for pattern in $line; do
|
||||||
for pattern in $line; do
|
if [[ "$pattern" =~ $exclude_pattern ]]; then
|
||||||
if [[ "$pattern" =~ $exclude_pattern ]]; then
|
for ex_file in ${BASH_REMATCH[1]}; do
|
||||||
for ex_file in ${BASH_REMATCH[1]}; do
|
if [ -e "$ex_file" ]; then
|
||||||
if [ -e "$ex_file" ]; then
|
ENCRYPT_EXCLUDE_FILES+=("$ex_file")
|
||||||
ENCRYPT_EXCLUDE_FILES+=("$ex_file")
|
fi
|
||||||
fi
|
done
|
||||||
done
|
else
|
||||||
else
|
for in_file in $pattern; do
|
||||||
for in_file in $pattern; do
|
if [ -e "$in_file" ]; then
|
||||||
if [ -e "$in_file" ]; then
|
ENCRYPT_INCLUDE_FILES+=("$in_file")
|
||||||
ENCRYPT_INCLUDE_FILES+=("$in_file")
|
fi
|
||||||
fi
|
done
|
||||||
done
|
fi
|
||||||
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; }
|
|
||||||
done
|
done
|
||||||
[ -n "$skip" ] || FINAL_INCLUDE+=("$included")
|
fi
|
||||||
done
|
done < "$YADM_ENCRYPT"
|
||||||
|
|
||||||
# sort the encrypted files
|
# remove excludes from the includes
|
||||||
#shellcheck disable=SC2207
|
#(SC2068 is disabled because in this case, we desire globbing)
|
||||||
IFS=$'\n' ENCRYPT_INCLUDE_FILES=($(LC_ALL=C sort <<<"${FINAL_INCLUDE[*]}"))
|
#shellcheck disable=SC2068
|
||||||
unset IFS
|
for included in "${ENCRYPT_INCLUDE_FILES[@]}"; do
|
||||||
fi
|
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
|
if [ "$unset_globstar" = "1" ]; then
|
||||||
shopt -u globstar &> /dev/null
|
shopt -u globstar &> /dev/null
|
||||||
|
|
Loading…
Reference in a new issue