Skip to content

Commit

Permalink
gupload: Handle more possible api errors when uploading
Browse files Browse the repository at this point in the history
Handle edgecase when curl http code is 000 in case of resumeable uploads

more robust checking when generating upload link
  • Loading branch information
Akianonymus committed Oct 20, 2020
1 parent 4889060 commit 39f8cfd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
10 changes: 7 additions & 3 deletions bash/drive-utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ _generate_upload_link() {
-D - || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

uploadlink="$(read -r firstline <<< "${uploadlink/*[L,l]ocation: /}" && printf "%s\n" "${firstline//$'\r'/}")"
{ [[ -n ${uploadlink} ]] && return 0; } || return 1
case "${uploadlink}" in
*'ocation: '*'upload_id'*) uploadlink="$(read -r firstline <<< "${uploadlink/*[L,l]ocation: /}" && printf "%s\n" "${firstline//$'\r'/}")" && return 0 ;;
'' | *) return 1 ;;
esac

return 0
}

# Curl command to push the file to google drive.
Expand Down Expand Up @@ -327,7 +331,7 @@ _upload_file() {
_full_upload || return 1
fi
;;
40[0-9]) # Dead Resumable URI give 40* status
40[0-9] | 000) # Dead Resumable URI give 40* status
_full_upload
;;
201 | 200) # Completed Resumable URI give 20* status
Expand Down
10 changes: 7 additions & 3 deletions bash/release/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,12 @@ _generate_upload_link() {
-D - || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

uploadlink="$(read -r firstline <<< "${uploadlink/*[L,l]ocation: /}" && printf "%s\n" "${firstline//$'\r'/}")"
{ [[ -n ${uploadlink} ]] && return 0; } || return 1
case "${uploadlink}" in
*'ocation: '*'upload_id'*) uploadlink="$(read -r firstline <<< "${uploadlink/*[L,l]ocation: /}" && printf "%s\n" "${firstline//$'\r'/}")" && return 0 ;;
'' | *) return 1 ;;
esac

return 0
}

# Curl command to push the file to google drive.
Expand Down Expand Up @@ -716,7 +720,7 @@ _upload_file() {
_full_upload || return 1
fi
;;
40[0-9]) # Dead Resumable URI give 40* status
40[0-9] | 000) # Dead Resumable URI give 40* status
_full_upload
;;
201 | 200) # Completed Resumable URI give 20* status
Expand Down
10 changes: 7 additions & 3 deletions sh/drive-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ _generate_upload_link() {
-D - || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

uploadlink_upload_file="$(printf "%s\n" "${uploadlink_upload_file##*[L,l]ocation: }" | while read -r line; do printf "%s\n" "${line%%$(printf '\r')}" && break; done)"
{ [ -n "${uploadlink_upload_file}" ] && return 0; } || return 1
case "${uploadlink_upload_file}" in
*'ocation: '*'upload_id'*) uploadlink_upload_file="$(printf "%s\n" "${uploadlink_upload_file##*[L,l]ocation: }" | while read -r line; do printf "%s\n" "${line%%$(printf '\r')}" && break; done)" && return 0 ;;
'' | *) return 1 ;;
esac
return 0
}
# Curl command to push the file to google drive.
Expand Down Expand Up @@ -329,7 +333,7 @@ _upload_file() {
_full_upload || return 1
fi
;;
40[0-9]) # Dead Resumable URI give 40* status
40[0-9] | 000) # Dead Resumable URI give 40* status
_full_upload
;;
201 | 200) # Completed Resumable URI give 20* status
Expand Down
10 changes: 7 additions & 3 deletions sh/release/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,12 @@ _generate_upload_link() {
-D - || :)" && _clear_line 1 1>&2
_clear_line 1 1>&2

uploadlink_upload_file="$(printf "%s\n" "${uploadlink_upload_file##*[L,l]ocation: }" | while read -r line; do printf "%s\n" "${line%%$(printf '\r')}" && break; done)"
{ [ -n "${uploadlink_upload_file}" ] && return 0; } || return 1
case "${uploadlink_upload_file}" in
*'ocation: '*'upload_id'*) uploadlink_upload_file="$(printf "%s\n" "${uploadlink_upload_file##*[L,l]ocation: }" | while read -r line; do printf "%s\n" "${line%%$(printf '\r')}" && break; done)" && return 0 ;;
'' | *) return 1 ;;
esac
return 0
}
# Curl command to push the file to google drive.
Expand Down Expand Up @@ -696,7 +700,7 @@ _upload_file() {
_full_upload || return 1
fi
;;
40[0-9]) # Dead Resumable URI give 40* status
40[0-9] | 000) # Dead Resumable URI give 40* status
_full_upload
;;
201 | 200) # Completed Resumable URI give 20* status
Expand Down

0 comments on commit 39f8cfd

Please sign in to comment.