[chk_nonexistent_ids] Added to check for TRACKIDs that point to non-existent files

This commit is contained in:
ayakael 2018-03-29 11:35:26 -04:00
parent c1d3609089
commit badc5c28c9
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026

31
src/chk_nonexistent_ids Normal file
View file

@ -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 </path/to/target/dir> </path/to/db/file/>
#
# }
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
}