[export_rm] Fixed bug where matching trackids, but one was to be removed, would both be removed, thus creating a remove-redeploy loop

This commit is contained in:
ayakael 2018-12-29 18:00:07 -05:00
parent a786821d8e
commit cfcd9fb697
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026

View file

@ -20,8 +20,15 @@ export_rm() {
local TRACKID=$(awk 'BEGIN{FS="--"}{print $3}' <<< ${3}) local TRACKID=$(awk 'BEGIN{FS="--"}{print $3}' <<< ${3})
## Removes trackids from TARGET ## Removes trackids from TARGET
_msg EXEC "Removing ${TRACKID} from ${TARGET}" _msg EXEC "Removing ${TRACKID} from ${TARGET})"
local pathList=($( awk -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($3==trackid && $4!="null"){print $4}})'))
if [[ ${#pathList[@]} -eq 1 ]]; then
rm "${TARGET}/$(print_present_path "${DB_FILE}" ${IMAGEID} ${TRACKID})" >${STDERR} 2>&1 rm "${TARGET}/$(print_present_path "${DB_FILE}" ${IMAGEID} ${TRACKID})" >${STDERR} 2>&1
[[ $? -eq 0 ]] && { _msg OK; gawk -i inplace -v trackid=${TRACKID} -v value=null 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE}; return 0; } || { _msg WARN; return 1; } else
echo "Detected multiple instances of ${TRACKID} with same paths, will not delete" > ${STDERR}
_msg WARN
fi
[[ $? -eq 0 ]] && { _msg OK; gawk -i inplace -v imageid=${IMAGEID} -v trackid=${TRACKID} -v value=null 'BEGIN{FS="\t";OFS="\t"}{if(($3==trackid && $2==imageid) && $1=="null"){$4=value}{print $0}}' ${DB_FILE}; return 0; } || { _msg WARN; return 1; }
} }