# Move everything but the log file to ./failed/ if codearchiver exited non-zero
# Verify that there are no artefacts if codearchiver exited non-zero
# Since codearchiver handles errors internally normally, this should not usually happen, but it could occur e.g. if running out of disk space and leaving partial files in the storage.
# With parallelism, this could in theory lead to artefacts of a successful run depending on artefacts from a failed run, which we wouldn't want.
# So, if there are artefacts of a failed process, touch the .tainted file to stop the uploader and new processes starting and send a warning to IRC.
# Emit the log filename for upload always (even on tainted storage), artefacts list and artefacts only on zero exit.
readarray -t artefacts <"${artefactsname}"
if [[ "${status}" -ne 0 ]]; then
msg="$(printf 'Moving artefact files'; printf ' %q' "${artefacts[@]}" "${artefactsname}"; printf ' from non-zero exit for job %s to ./failed/\n' "${singlejobid}";)"
if [[ "${status}" -ne 0 && "${#artefacts[@]}" -ne 0 ]]; then
touch '.tainted'
send "Job ${singlejobid} exited non-zero but left artefacts behind!"