Skip to content

Commit a55a966

Browse files
committed
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.
1 parent 009b631 commit a55a966

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tasks/download.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ download() {
4646

4747
if curl -s -f -L -o ${tmp_file} "$1"; then
4848
echo "Moving ${tmp_file} to target path ${2}"
49-
mv "${tmp_file}" "$2"
50-
return 0
49+
50+
# Perform the move. If it doesn't work, clean up and return an error
51+
if ! mv "${tmp_file}" "$2"; then
52+
echo "Failed to move ${tmp_file} to ${2}! Deleting temporary file"
53+
rm "${tmp_file}"
54+
return 1
55+
fi
5156
else
5257
echo "Error: Curl has failed to download the file"
5358
echo "Removing temporary file ${tmp_file}"
@@ -94,7 +99,7 @@ download-signature-verify() {
9499
download-size-verify "$source" "$path"
95100
elif [[ "$verify_exit" -eq "1" ]]; then
96101
echo "$verify_output"
97-
download "$source" "$path"
102+
download "$source" "$path" || return 1
98103
echo "Verifying ${path}..."
99104
verify-file "${path}.asc" "$path"
100105
fi

0 commit comments

Comments
 (0)