From badc5c28c9e76e32c0c5f95403ef1964c4a7de5a Mon Sep 17 00:00:00 2001 From: ayakael Date: Thu, 29 Mar 2018 11:35:26 -0400 Subject: [PATCH] [chk_nonexistent_ids] Added to check for TRACKIDs that point to non-existent files --- src/chk_nonexistent_ids | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/chk_nonexistent_ids diff --git a/src/chk_nonexistent_ids b/src/chk_nonexistent_ids new file mode 100644 index 0000000..b7c608c --- /dev/null +++ b/src/chk_nonexistent_ids @@ -0,0 +1,31 @@ +#!/bin/bash + +# doc chk_nonexistent_ids { +# +# DESCRIPTION +# chk_nonexistent_ids - Checks if all trackids in DB_FILE points to an existing file. If not, deletes. +# +# USAGE +# chk_nonexistent_ids +# +# } + +chk_nonexistent_ids() { + local TARGET="${1}" + local DB_FILE="${2}" + + for row in $(awk 'BEGIN{RS="\n";FS="\t";OFS="="}{print $2,$3,$4}' ${DB_FILE}); do + local IMAGEID="$(cut -d"=" -f1 <<< ${row})" + local TRACKID="$(cut -d"=" -f2 <<< ${row})" + local FILE="$(cut -d"=" -f3 <<< ${row})" + _msg ECHO "Checking track id ${TRACKID}" + + if [[ ! -f "${TARGET}/${FILE}" ]] && [[ ${FILE} != "null" ]]; then + _msg ECHO "${TRACKID} points to non-existent file" + sed -i "/${IMAGEID} ${TRACKID}/d" ${DB_FILE} + fi + done + +} + +