Skip to content

Commit

Permalink
Switched to fail strategy for folder creation.
Browse files Browse the repository at this point in the history
The script should not create folders with different names
when it fails to find the already existing folder.

This refs #12.
  • Loading branch information
fkalis committed Dec 3, 2015
1 parent d397000 commit b1f663e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions onedrive-base
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export -f curl_get_children_of_root
# $1=parent_folder_id
# $2=new_folder_name
function curl_create_folder() {
local json_payload="{\"name\":\"$2\",\"folder\":{},\"@name.conflictBehavior\":\"rename\"}"
local json_payload="{\"name\":\"$2\",\"folder\":{},\"@name.conflictBehavior\":\"fail\"}"
local url

if [ -z "$1" ]; then
Expand Down Expand Up @@ -120,7 +120,7 @@ export -f curl_upload_file
function curl_request_upload_session() {
local raw_filename=$(basename "$2")
local filename=$(urlencode "${raw_filename}")
local json_payload="{\"item\":{\"@name.conflictBehavior\":\"rename\",\"name\":\"${raw_filename}\"}}"
local json_payload="{\"item\":{\"@name.conflictBehavior\":\"replace\",\"name\":\"${raw_filename}\"}}"
local folder_id=$(urlencode "$1")
local file
local url
Expand Down Expand Up @@ -344,7 +344,7 @@ function onedrive_upload_file_simple() {
exit_on_error

local status_code=$(curl_upload_file "${api_folder_id}" "$1")
if (( "${status_code}" == 200 || "${status_code}" == 201 )); then
if [ "${status_code}" == "200" ] || [ "${status_code}" == "201" ]; then
echo "Successfully uploaded '$1'"
else
error "An error has occurred while uploading '$1' (Code: ${status_code})"
Expand Down Expand Up @@ -375,15 +375,17 @@ function onedrive_upload_file_chunked() {

status_code=$(curl_upload_chunk "${upload_url}" "${current_chunk}" "$1" "${filesize}")

if [ ! "${status_code}" == "201" ] && [ ! "${status_code}" == "202" ] && [ ! "${status_code}" == "204" ]; then
debug "Upload of chunk ${current_chunk} finished (Code: ${status_code})"

if [ ! "${status_code}" == "200" ] && [ ! "${status_code}" == "201" ] && [ ! "${status_code}" == "202" ] && [ ! "${status_code}" == "204" ]; then
curl_delete_upload_session "${upload_url}"
error "An error has occurred while uploading '$1' (Code: ${status_code})"
fi

current_chunk=$((${current_chunk}+1))
done

if [ ! "${status_code}" == "201" ]; then
if [ ! "${status_code}" == "200" ] && [ ! "${status_code}" == "201" ]; then
error "An error has occured while uploading '$1' (Code: ${status_code})"
fi

Expand Down

0 comments on commit b1f663e

Please sign in to comment.