[parser][cmd_fsck][chk_duplicate_trackid] Added function to check for duplicate trackids

This commit is contained in:
ayakael 2019-02-12 21:24:13 -05:00
parent ada07ad3a9
commit db443fa032
No known key found for this signature in database
GPG key ID: DF4ED0DE242BD38A
3 changed files with 34 additions and 1 deletions

24
src/chk_duplicate_trackid Normal file
View file

@ -0,0 +1,24 @@
#!/bin/bash
chk_duplicate_trackid() {
local DB_FILE="${1}"
shift
local trackidList=(${@})
[ -z ${trackidList+x} ] && local trackidList=($(awk 'BEGIN{FS="\t"}{print $3}' ${DB_FILE} | awk '!seen[$0]++'))
local COUNT=1
for trackid in ${trackidList[@]}; do
echo "[ ${COUNT} / ${#trackidList[@]} ] Checking duplicate ${trackid} in ${DB_FILE}"
local curtrackidList=($(awk -v trackid=${trackid} 'BEGIN{FS="\t"}{if($3==trackid){print $3}}' ${DB_FILE}))
if [[ ${#curtrackidList[@]} -gt 1 ]]; then
_ansi up 2; echo -en '\033[K'; echo "[ ${COUNT} / ${#trackidList[@]} ] ${trackid} duplicate"
local duplicatetrackidList=(${duplicatetrackidList[@]} ${trackid})
local ERR=true
else
_ansi up 2; echo -en '\033[K'; echo "[ ${COUNT} / ${#trackidList[@]} ] ${trackid} not duplicate"
fi
local COUNT=$(( ${COUNT} + 1 ))
done
printf "Duplicate track: %s\n" ${duplicatetrackidList[@]} > ${STDERR}
[[ "${ERR}" == "true" ]] && { _msg EXEC "Duplicate trackid check completed with errors"; _msg WARN; } || { _msg EXEC "Duplicate trackid check completed succesfully"; _msg OK; }
}

View file

@ -34,6 +34,10 @@ cmd_fsck() {
metadata)
chk_metadata "${GIT_DIR}" "${TARGET}" "${DB_FILE}"
;;
duplicate-trackid)
chk_duplicate_trackid "${DB_FILE}"
;;
esac
done
}

View file

@ -176,6 +176,11 @@ case "${1}" in
shift
;;
--duplicate-trackid)
cmdList=(${cmdList[@]} duplicate-trackid)
shift
;;
*)
TARGET="${1}"
shift
@ -184,7 +189,7 @@ case "${1}" in
esac
done
[[ -z ${cmdList[@]} ]] && cmdList=(deployed-ids nonexistent-ids metadata)
[[ -z ${cmdList[@]} ]] && cmdList=(deployed-ids nonexistent-ids metadata duplicate-trackid)
cmd_fsck "${_GIT_DIR}" "${TARGET}" ${cmdList[@]}
EXIT=$?