[db_update] Now only processes one IMAGEID at a time

This commit is contained in:
ayakael 2018-04-07 22:48:02 -04:00
parent 5034f4c1bb
commit a9c9e80c06
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026

View file

@ -6,30 +6,28 @@
# db_update - Updates TARGET's DB_FILE with defined IMAGEIDs
#
# USAGE
# db_update <path/to/git/dir> <path/to/target/dir> <path/to/db/file> <IMAGEID> <...>
# db_update <path/to/git/dir> <path/to/target/dir> <path/to/db/file> <IMAGEID>
#
# }
db_update() {
local GIT_DIR="${1}"
local TARGET="${2}"
local DB_FILE="${3}"; shift 3
local imageidList=(${@})
local DB_FILE="${3}"
local IMAGEID="${4}"
[[ -f "${DB_FILE}" ]] || touch "${DB_FILE}"
for imageid in ${imageidList[@]}; do
trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}' ${GIT_DIR}/${imageid}.tags))
if [[ -f ${GIT_DIR}/${imageid}.tags ]]; then
_msg ECHO "Removing ${imageid} from database file"
gawk -i inplace -v imageid="${imageid}" 'BEGIN{FS="\t";OFS="\t"}{if($2=imageid){$1="null"}{print $0}}' ${DB_FILE}
trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}' ${GIT_DIR}/${IMAGEID}.tags))
if [[ -f ${GIT_DIR}/${IMAGEID}.tags ]]; then
_msg ECHO "Removing ${IMAGEID} from database file"
gawk -i inplace -v imageid="${IMAGEID}" 'BEGIN{FS="\t";OFS="\t"}{if($2=imageid){$1="null"}{print $0}}' ${DB_FILE}
continue
fi
for trackid in ${trackidList[@]}; do
if [[ -z $(awk -v imageid="${imageid}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]]; then
_msg ECHO "Adding ${trackid} of ${imageid} to database file"
echo -e "true\t${imageid}\t${trackid}\tnull" >> ${DB_FILE}
if [[ -z $(awk -v imageid="${IMAGEID}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]]; then
_msg ECHO "Adding ${trackid} of ${IMAGEID} to database file"
echo -e "true\t${IMAGEID}\t${trackid}\tnull" >> ${DB_FILE}
fi
done
done
return 0
}