2018-03-29 11:35:26 -04:00
|
|
|
#!/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}"
|
|
|
|
|
2018-04-07 19:59:47 -04:00
|
|
|
local ERR=false
|
2018-04-15 22:22:44 -04:00
|
|
|
local rowList=($(awk 'BEGIN{RS="\n";FS="\t";OFS="="}{if($1!="LAST_UPDATE" || $1!="LAST_DEPLOY"){print $2,$3,$4}}' "${DB_FILE}"))
|
2018-04-07 19:59:47 -04:00
|
|
|
|
|
|
|
local COUNT=1
|
|
|
|
for row in ${rowList[@]}; do
|
2018-03-29 11:35:26 -04:00
|
|
|
local IMAGEID="$(cut -d"=" -f1 <<< ${row})"
|
|
|
|
local TRACKID="$(cut -d"=" -f2 <<< ${row})"
|
|
|
|
local FILE="$(cut -d"=" -f3 <<< ${row})"
|
2018-04-07 19:59:47 -04:00
|
|
|
|
|
|
|
echo "[ ${COUNT} / ${#rowList[@]} ] Checking path of ${TRACKID}"
|
|
|
|
|
2018-03-29 11:35:26 -04:00
|
|
|
if [[ ! -f "${TARGET}/${FILE}" ]] && [[ ${FILE} != "null" ]]; then
|
2018-04-15 22:21:06 -04:00
|
|
|
gawk -i inplace -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t";OFS="\t"}{if($2==imageid && $3==trackid){$4="null"}{print $0}}' ${DB_FILE}
|
2018-04-07 19:59:47 -04:00
|
|
|
local $?=1
|
2018-03-29 11:35:26 -04:00
|
|
|
fi
|
2018-04-07 22:43:55 -04:00
|
|
|
[[ $? -eq 0 ]] || { echo "[>>>>>>] Error reported"; echo "${TRACKID} of ${IMAGEID} points to non-existent file"}; local ERR=true; }
|
2018-04-07 19:59:47 -04:00
|
|
|
local COUNT=$(( ${COUNT} + 1 ))
|
2018-03-29 11:35:26 -04:00
|
|
|
done
|
2018-04-15 22:40:31 -04:00
|
|
|
[[ "${ERR}" == "true" ]] && return 1 || return 0
|
2018-03-29 11:35:26 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|