From a55a966274b826f7a583ba4ba8c6e1a96dd53df7 Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Mon, 4 Oct 2021 09:27:05 -0700 Subject: [PATCH] Catch mv errors when downloading If moving the temporary file into the final location fails, make sure that error is caught and return values set appropriately. --- tasks/download.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tasks/download.sh b/tasks/download.sh index fa2ca79d..7612347b 100755 --- a/tasks/download.sh +++ b/tasks/download.sh @@ -46,8 +46,13 @@ download() { if curl -s -f -L -o ${tmp_file} "$1"; then echo "Moving ${tmp_file} to target path ${2}" - mv "${tmp_file}" "$2" - return 0 + + # Perform the move. If it doesn't work, clean up and return an error + if ! mv "${tmp_file}" "$2"; then + echo "Failed to move ${tmp_file} to ${2}! Deleting temporary file" + rm "${tmp_file}" + return 1 + fi else echo "Error: Curl has failed to download the file" echo "Removing temporary file ${tmp_file}" @@ -94,7 +99,7 @@ download-signature-verify() { download-size-verify "$source" "$path" elif [[ "$verify_exit" -eq "1" ]]; then echo "$verify_output" - download "$source" "$path" + download "$source" "$path" || return 1 echo "Verifying ${path}..." verify-file "${path}.asc" "$path" fi