Skip to content

Commit

Permalink
upload: Fix interrupted upload
Browse files Browse the repository at this point in the history
Adjust some logging
  • Loading branch information
Akianonymus committed Jul 26, 2020
1 parent 35600cb commit 15afdb3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
9 changes: 5 additions & 4 deletions bash/drive-utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ _upload_file_from_uri() {
-o- \
--url "${uploadlink}" \
--globoff \
${CURL_SPEED} ${resume_args} || :)"
[[ -z ${VERBOSE_PROGRESS} ]] && for _ in 1 2; do _clear_line 1; done
${CURL_SPEED} ${resume_args1} ${resume_args2} \
-H "${resume_args3}" || :)"
[[ -z ${VERBOSE_PROGRESS} ]] && for _ in 1 2; do _clear_line 1; done && "${1:-:}"
return 0
}
# logging in case of successful upload
Expand Down Expand Up @@ -295,8 +296,8 @@ _upload_file() {
content_range="$(printf "bytes %s-%s/%s\n" "$((uploaded_range + 1))" "$((inputsize - 1))" "${inputsize}")"
content_length="$((inputsize - $((uploaded_range + 1))))"
# Resuming interrupted uploads needs http1.1
resume_args='-s --http1.1 -H "Content-Range: '${content_range}'"'
_upload_file_from_uri
resume_args1='-s' resume_args2='--http1.1' resume_args3="Content-Range: ${content_range}"
_upload_file_from_uri _clear_line
_collect_file_info "${upload_body}" "${slug}" || return 1
_normal_logging_upload
_remove_upload_session
Expand Down
6 changes: 3 additions & 3 deletions bash/upload.bash
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ _process_arguments() {

_print_center "justify" "Given Input" ": FOLDER" "-"
_print_center "justify" "Upload Method" ": ${SKIP_DUPLICATES:-${OVERWRITE:-Create}}" "=" && _newline "\n"
FOLDER_NAME="${input##*/}" && _print_center "justify" "Folder: ${FOLDER_NAME}" "="
FOLDER_NAME="${input##*/}" && "${EXTRA_LOG}" "justify" "Folder: ${FOLDER_NAME}" "="

NEXTROOTDIRID="${WORKSPACE_FOLDER_ID}"

Expand All @@ -541,7 +541,7 @@ _process_arguments() {
# Skip the sub folders and find recursively all the files and upload them.
if [[ -n ${SKIP_SUBDIRS} ]]; then
if [[ -n ${FILENAMES[0]} ]]; then
_clear_line 1
for _ in 1 2; do _clear_line 1; done
NO_OF_FILES="${#FILENAMES[@]}"

"${QUIET:-_print_center}" "justify" "Folder: ${FOLDER_NAME} " "| ${NO_OF_FILES} File(s)" "=" && printf "\n"
Expand All @@ -558,7 +558,7 @@ _process_arguments() {
fi
else
if [[ -n ${FILENAMES[0]} ]]; then
_clear_line 1
for _ in 1 2; do _clear_line 1; done
NO_OF_FILES="${#FILENAMES[@]}"
"${QUIET:-_print_center}" "justify" "${FOLDER_NAME} " "| ${NO_OF_FILES} File(s) | ${NO_OF_SUB_FOLDERS} Sub-folders" "="

Expand Down
11 changes: 6 additions & 5 deletions sh/drive-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ _upload_file_from_uri() {
-o- \
--url "${uploadlink_upload_file}" \
--globoff \
${CURL_SPEED} ${resume_args_upload_file} || :)"
[ -z "${VERBOSE_PROGRESS}" ] && for _ in 1 2; do _clear_line 1; done
${CURL_SPEED} ${resume_args1} ${resume_args2} \
-H "${resume_args3}" || :)"
[ -z "${VERBOSE_PROGRESS}" ] && for _ in 1 2; do _clear_line 1; done && "${1:-:}"
return 0
}
Expand Down Expand Up @@ -285,7 +286,7 @@ _upload_file() {
# https://developers.google.com/drive/api/v3/manage-uploads
if [ -r "${__file_upload_file}" ]; then
uploadlink_upload_file="$(cat "${__file_upload_file}" || :)"
http_code_upload_file="$(curl --compressed -s -X PUT "${uploadlink_upload_file}" --write-out %"{http_code_upload_file}")" || :
http_code_upload_file="$(curl --compressed -s -X PUT "${uploadlink_upload_file}" --write-out %"{http_code}")" || :
case "${http_code_upload_file}" in
308) # Active Resumable URI give 308 status
uploaded_range_upload_file="$(raw_upload_file="$(curl --compressed -s -X PUT \
Expand All @@ -297,8 +298,8 @@ _upload_file() {
content_range_upload_file="$(printf "bytes %s-%s/%s\n" "$((uploaded_range_upload_file + 1))" "$((inputsize_upload_file - 1))" "${inputsize_upload_file}")"
content_length_upload_file="$((inputsize_upload_file - $((uploaded_range_upload_file + 1))))"
# Resuming interrupted uploads needs http1.1
resume_args_upload_file='-s --http1.1 -H "Content-Range: '${content_range_upload_file}'"'
_upload_file_from_uri
resume_args1='-s' resume_args2='--http1.1' resume_args3="Content-Range: ${content_range_upload_file}"
_upload_file_from_uri _clear_line
_collect_file_info "${upload_body_upload_file}" "${slug_upload_file}" || return 1
_normal_logging_upload
_remove_upload_session
Expand Down
6 changes: 3 additions & 3 deletions sh/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ _process_arguments() {
_print_center "justify" "Given Input" ": FOLDER" "-"
_print_center "justify" "Upload Method" ": ${SKIP_DUPLICATES:-${OVERWRITE:-Create}}" "=" && _newline "\n"
FOLDER_NAME="${input##*/}" && _print_center "justify" "Folder: ${FOLDER_NAME}" "="
FOLDER_NAME="${input##*/}" && "${EXTRA_LOG}" "justify" "Folder: ${FOLDER_NAME}" "="
NEXTROOTDIRID="${WORKSPACE_FOLDER_ID}"
Expand All @@ -558,7 +558,7 @@ _process_arguments() {
if [ -n "${SKIP_SUBDIRS}" ]; then
if [ -n "${FILENAMES}" ]; then
NO_OF_FILES="$(($(printf "%s\n" "${FILENAMES}" | wc -l)))"
_clear_line 1
for _ in 1 2; do _clear_line 1; done
"${QUIET:-_print_center}" "justify" "Folder: ${FOLDER_NAME} " "| ${NO_OF_FILES} File(s)" "=" && printf "\n"
"${EXTRA_LOG}" "justify" "Creating folder.." "-"
Expand All @@ -575,7 +575,7 @@ _process_arguments() {
else
if [ -n "${FILENAMES}" ]; then
NO_OF_FILES="$(($(printf "%s\n" "${FILENAMES}" | wc -l)))"
_clear_line 1
for _ in 1 2; do _clear_line 1; done
"${QUIET:-_print_center}" "justify" "${FOLDER_NAME} " "| $((NO_OF_FILES)) File(s) | $((NO_OF_SUB_FOLDERS)) Sub-folders" "="
_newline "\n" && "${EXTRA_LOG}" "justify" "Creating Folder(s).." "-" && _newline "\n"
Expand Down

0 comments on commit 15afdb3

Please sign in to comment.