From 99733b390d56e7c97f6f09bbb2af667013514391 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.anjos@idiap.ch>
Date: Fri, 23 Jun 2017 16:09:15 +0200
Subject: [PATCH] Simplify logging on curl uploads

---
 gitlab/functions.sh | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/gitlab/functions.sh b/gitlab/functions.sh
index 1486fcd..45d742d 100644
--- a/gitlab/functions.sh
+++ b/gitlab/functions.sh
@@ -192,8 +192,6 @@ setup_deploy() {
 # $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_upload() {
-  log_info "curl: ${1} -> ${DOCSERVER}/${2}..."
-
   if [ ! -e $1 ]; then
     log_error "File \`${1}\' does not exist on the local disk"
     exit 1
@@ -201,7 +199,7 @@ dav_upload() {
 
   local code=`curl --location --silent --fail --write-out "%{http_code}" --user "${DOCUSER}:${DOCPASS}" --upload-file ${1} ${DOCSERVER}/${2}`
   if [[ ${code} == *204 || ${code} == *201 ]]; then
-    log_info "Successfully uploaded ${1} with curl"
+    log_info "curl: cp ${1} -> ${DOCSERVER}/${2}..."
   else
     log_error "Curl command finished with an error condition (code=${code}):"
     curl --location --silent --user "${DOCUSER}:${DOCPASS}" --upload-file ${1} ${DOCSERVER}/${2}
@@ -213,12 +211,10 @@ dav_upload() {
 # Creates a folder at our intranet location via curl
 # $1: Path of the folder to create (e.g. private-upload/docs/test-folder)
 dav_mkdir() {
-  log_info "curl: MKDIR ${DOCSERVER}/${1}..."
-
   local code=$(curl --location --silent --fail --write-out "%{http_code}" --user "${DOCUSER}:${DOCPASS}" -X MKCOL "${DOCSERVER}/${1}")
 
   if [[ ${code} == *204 || ${code} == *201 ]]; then
-    log_info "Successfully created ${1} with curl"
+    log_info "curl: mkdir ${DOCSERVER}/${1}"
   else
     log_error "Curl command finished with an error condition (code=${code}):"
     curl --location --silent --user "${DOCUSER}:${DOCPASS}" -X MKCOL "${DOCSERVER}/${1}"
@@ -230,20 +226,19 @@ dav_mkdir() {
 # Deletes a file/folder from our intranet location via curl
 # $1: Path to the file/folder to delete (e.g. dist/myfile.whl)
 dav_delete() {
-  log_info "curl: EXISTS ${DOCSERVER}/${1}?"
+  log_info "curl: exists ${DOCSERVER}/${1}?"
 
   # checks if the directory exists before trying to remove it (use --head)
   local code=$(curl --location --silent --fail --write-out "%{http_code}" --head --user "${DOCUSER}:${DOCPASS}" "${DOCSERVER}/$1")
   if [[ ${code} == *404 ]]; then
-    log_info "Directory $1 does not exist. Skipping deletion"
+    log_info "Directory ${DOCSERVER}/$1 does not exist. Skipping deletion"
     return 0
   fi
 
-  log_info "curl: DELETE ${DOCSERVER}/${1}..."
   code=$(curl --location --silent --fail --write-out "%{http_code}" --user "${DOCUSER}:${DOCPASS}" -X DELETE "${DOCSERVER}/$1")
 
   if [[ ${code} == *204 || ${code} == *201 ]]; then
-    log_info "Successfully deleted ${DOCSERVER}/${1} with curl"
+    log_info "curl: rm -rf ${DOCSERVER}/${1}"
   else
     log_error "Curl command finished with an error condition (code=${code}):"
     curl --location --silent --user "${DOCUSER}:${DOCPASS}" -X DELETE "${DOCSERVER}/$1"
@@ -256,7 +251,7 @@ dav_delete() {
 # $1: Path to the folder to upload (e.g. test-folder/)
 # $2: Path on the server to upload to (e.g. private-upload/docs/test/ to put contents of test-folder/ in test/)
 dav_upload_folder() {
-  log_info "curl: ${1} -> ${DOCSERVER}/${2}..."
+  log_info "curl: cp -r ${1} -> ${DOCSERVER}/${2}..."
 
   if [ ! -e $1 ]; then
     log_error "Directory \`${1}\' does not exist on the local disk"
@@ -268,7 +263,7 @@ dav_upload_folder() {
     # with the server path prefix ('private-upload/docs/test/')
     # to make something like '../folder1/folder2/folder-to-upload/test.txt'
     # into 'private-upload/docs/test.txt'
-    local server_path="${fname/$1/$2}"
+    local server_path="${fname/$1\//$2}"
 
     # if its a file...
     if [[ -f "${fname}" ]]; then
@@ -278,8 +273,6 @@ dav_upload_folder() {
       # if its a dir, create the dir
       dav_mkdir "${server_path}"
     fi
-
-    log_info "Successfully copied folder ${1} with curl"
   done
 }
 
-- 
GitLab