From 214486a5b778eceec52baefb10f94ebe0544497d Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Sat, 17 Feb 2018 14:17:41 +0100 Subject: [PATCH] Uploads files to the DAV server with a check --- gitlab/functions.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/gitlab/functions.sh b/gitlab/functions.sh index e8797d0..7c4c02a 100644 --- a/gitlab/functions.sh +++ b/gitlab/functions.sh @@ -119,6 +119,14 @@ run_cmd() { } +# Checks if a file exists on the remote location +# $1: Path to the file to check on the server +dav_exists() { + curl --head --silent --location ${DOCSERVER}/${1} | grep HTTP | tail -n 1 | grep -q 200 + return $? +} + + # Uploads a file to our intranet location via curl # $1: Path to the file to upload (e.g. dist/myfile.whl) # $2: Path on the server to upload to (e.g. private-upload/wheels/gitlab/) @@ -139,6 +147,20 @@ dav_upload() { } +# Uploads a file to our intranet location via curl, if (and only if) it does +# not exist on the remote server +# $1: Path to the file to upload (e.g. dist/myfile.whl) +# $2: Path on the server to upload to (e.g. private-upload/wheels/gitlab/) +dav_check_upload() { + local remote_name=${2}/$(basename ${1}) + if dav_exists ${remote_name}; then + log_info "File \`${remote_name}' already exists on the remote server (not uploading again)" + else + dav_upload ${1} ${2} + fi +} + + # Creates a folder at our intranet location via curl # $1: Path of the folder to create (e.g. private-upload/docs/test-folder) # $2: which HTTP response code it should return instead of exit on (e.g. 405 means the folder already exists) @@ -244,17 +266,6 @@ dav_upload_folder() { } -# Checks if an array contains a value -# taken from here: https://stackoverflow.com/questions/3685970/check-if-an-array-contains-a-value -# Parameters: <value-to-check> <array-variable> -# Usage: "a string" "${array[@]}" -contains_element () { - local e - for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done - return 1 -} - - if [ -z "${BOB_PACKAGE_VERSION}" ]; then if [ ! -r "version.txt" ]; then log_error "./version.txt does not exist - cannot figure out version number" -- GitLab