[export_cp] Fixed error handling for export_mv. TODO: Fix it better; [cmd_export] Fixed deployableidList generation

This commit is contained in:
ayakael 2019-02-27 15:40:34 -05:00
parent 45b2e27c31
commit f26394aa65
Signed by untrusted user who does not match committer: forge
GPG key ID: D62A472A4AA7D541
4 changed files with 7 additions and 7 deletions

View file

@ -30,14 +30,14 @@ cmd_export() {
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
[[ -z "${OLD_COMMIT}" ]] && local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_DEPLOY"){print $2}}' "${DB_FILE}")
local removableidList=($(awk 'BEGIN{FS="\t"}{if(($1=="null" || $1=="false") && $4!="null"){print $2"--"$3}}' "${DB_FILE}"))
local exportableidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4=="null"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++'))
local deployableidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4=="null"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++'))
local changedidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
local selectedidList=($(awk 'BEGIN{FS="\t"}{if($1=="true"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++'))
for changedid in ${changedidList[@]}; do
if _if_array_contains ${changedid} ${selectedidList[@]}; then updateableidList=(${updateableidList[@]} ${changedid}); fi
done
local exportableidList=($(printf "%s\n" ${exportableidList[@]} ${updateableidList[@]} | awk '!seen[$0]++'))
local exportableidList=($(printf "%s\n" ${deployableidList[@]} ${updateableidList[@]} | awk '!seen[$0]++'))
# Checks if something needs doing
if [[ -z "${removableidList[@]}" ]] && [[ -z "${exportableidList[@]}" ]]; then echo "Nothing to do"; fi
@ -81,7 +81,7 @@ cmd_export() {
local EXIT=$?
[[ ${EXIT} -ne 0 ]] && local CP_ERR=true
[[ "${GIT_GET}" == "true" ]] && git -C "${GIT_DIR}" annex drop ${imageid}.flac >/dev/null 2>&1
[[ "${CP_ERR}" == "true" ]] && { _ansi up 2; echo -en '\033[K'; echo "[ ${COUNT} / ${#exportableidList[@]} ] Copy of ${imageid} completed with errors"; cat ${STDERR}; local ERR=true; continue; } || { if ${_DEBUG}; then cat ${STDERR}; fi; }
[[ "${CP_ERR}" == "true" ]] && { _ansi up 2; echo -en '\033[K'; echo "[ ${COUNT} / ${#exportableidList[@]} ] Copy of ${imageid} completed with error code ${EXIT}"; cat ${STDERR}; local ERR=true; continue; } || { if ${_DEBUG}; then cat ${STDERR}; fi; }
fi

View file

@ -27,8 +27,6 @@ export_cp() {
local EXIT=$?
[[ ${EXIT} -ne 0 ]] && return 1
export_mv "${GIT_DIR}" ${IMAGEID} >${STDERR} 2>&1
local EXIT=$?
[[ ${EXIT} -ne 0 ]] && return 2
## Transfers selected TRACKIDs to TARGET
trackidList=($(awk -v imageid=${IMAGEID} 'BEGIN{FS="\t"}{if($1=="true" && $2==imageid && $4=="null"){print $3}}' "${DB_FILE}"))

View file

@ -46,7 +46,7 @@ export_meta() {
mv "${TARGET}/${PRESENT_PATH}" "${TARGET}/${FUTURE_PATH}"
[[ $? -eq 0 ]] || local ERR=true
rmdir -p --ignore-fail-on-non-empty "$(dirname "${TARGET}/${PRESENT_PATH}")" >/dev/null 2>&1
gawk -i inplace -v trackid=${trackid} -v value="${FUTURE_PATH}" 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE}
[[ -f "${FUTURE_PATH}" ]] && gawk -i inplace -v trackid=${trackid} -v value="${FUTURE_PATH}" 'BEGIN{FS="\t";OFS="\t"}{if($3==trackid){$4=value}{print $0}}' ${DB_FILE}
fi
done
[[ "${ERR}" == "true" ]] && return 1 || return 0

View file

@ -12,6 +12,7 @@
export_mv() {
local GITDIR="${1}"
local IMAGEID="${2}"
local ERROR=false
# Generated trackidList to know what id to assign to each file
local trackidList=$(awk -v field="\"TRACKID\"" 'BEGIN{RS="[,]?\n";FS=" : "}{if($1~field){print $2}}' "${GITDIR}/${IMAGEID}.tags" | tr -d '"')
@ -20,7 +21,8 @@ export_mv() {
local COUNT=1
for trackid in ${trackidList[@]}; do
mv "${GITDIR}/$(printf 'split-track%02d.flac' ${COUNT})" "${GITDIR}/${IMAGEID}-${trackid}.flac"
[[ $? -ne 0 ]]; local ERROR=true
local EXIT=$?
[[ ${EXIT} -ne 0 ]]; local ERROR=true
local COUNT=$(( ${COUNT} + 1 ))
done
[[ "${ERROR}" == "true" ]] && return 1 || return 0