From 1ded1a99e03d20cf4b6ea4e0cdc2e77a226087d6 Mon Sep 17 00:00:00 2001 From: ayakael Date: Wed, 28 Mar 2018 11:29:07 -0400 Subject: [PATCH] Added _msg functions to deploy_imageid and update_db --- src/deploy_imageid | 4 +++- src/deploy_trackid | 4 ++-- src/update_db | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/deploy_imageid b/src/deploy_imageid index 5b731d2..0d65a37 100644 --- a/src/deploy_imageid +++ b/src/deploy_imageid @@ -21,9 +21,11 @@ deploy_imageid() { local trackidList=($(awk -v imageid=${IMAGEID} 'BEGIN{FS="\t"}{if($2==imageid){print $3}}' ${DB_FILE})) for trackid in ${trackidList[@]}; do - _msg ECHO "Processing ${trackid} of ${IMAGEID}" + _msg EXEC "Processing ${trackid} of ${IMAGEID}" deploy_trackid ${GIT_DIR} ${TARGET} ${DB_FILE} ${IMAGEID} ${trackid} + [[ $? -ne 0 ]] && { _msg WARN; local ERR=true; } || _msg OK done + [[ ${ERR} ]] && return 1 || return 0 } diff --git a/src/deploy_trackid b/src/deploy_trackid index 6a159b9..c11fe00 100644 --- a/src/deploy_trackid +++ b/src/deploy_trackid @@ -40,7 +40,7 @@ deploy_trackid() { # If the PRESENT_META and FUTURE_META diverge, wipe the old metadata, and reapply if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then - _msg ECHO "${TRACKID} has different metadata. Updating" + _msg ECHO "${TRACKID} has differing metadata. Updating" [[ "${PRESENT_PATH}" == "null" ]] || metaflac --remove-all "${TARGET}/${PRESENT_PATH}" awk 'BEGIN {RS=";"}{print $0}' <<< ${FUTURE_META} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${TARGET}/${PRESENT_PATH}" fi @@ -50,6 +50,7 @@ deploy_trackid() { _msg ECHO "${TRACKID} has differing paths. Moving" mkdir -p "$(dirname "${TARGET}/${FUTURE_PATH}")" mv "${TARGET}/${PRESENT_PATH}" "${TARGET}/${FUTURE_PATH}" + rmdir -p --ignore-fail-on-non-empty "$(dirname "${TARGET}/${PRESENT_PATH}")" awk -v rowno=${ROW_NO} -v value="${FUTURE_PATH}" 'BEGIN{FS="\t";OFS="\t"}{if(NR==rowno){$4=value}{print $0}}' ${DB_FILE} > ${DB_FILE}.tmp; mv ${DB_FILE}.tmp ${DB_FILE} fi @@ -63,5 +64,4 @@ deploy_trackid() { rm "${GIT_DIR}/${IMAGEID}-${TRACKID}.flac" fi fi - return 0 } diff --git a/src/update_db b/src/update_db index fddd3f6..231df10 100644 --- a/src/update_db +++ b/src/update_db @@ -20,7 +20,11 @@ update_db() { for imageid in ${imageidList[@]}; do trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}' ${GIT_DIR}/${imageid}.tags)) for trackid in ${trackidList[@]}; do - [[ -z $(awk -v imageid="${imageid}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]] && echo -e "true\t${imageid}\t${trackid}\tnull" >> ${DB_FILE} + if [[ -z $(awk -v imageid="${imageid}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]]; then + _msg ECHO "Adding ${trackid} of ${imageid} to database file" + echo -e "true\t${imageid}\t${trackid}\tnull" >> ${DB_FILE} + fi done done + return 0 }