diff --git a/gitlab/functions.sh b/gitlab/functions.sh index e8797d0025b610418d3a361b713b646752444a8f..7c4c02a0199bd488193a185283f8be37de624d3c 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"