From 5505fda9acec4345cc161f900358f78e81cf2068 Mon Sep 17 00:00:00 2001
From: ricolin <rico.lin.guanyu@gmail.com>
Date: Tue, 15 Sep 2020 14:06:07 +0800
Subject: [PATCH] Allow skip files when download logs

Allow skip files that fail to get the contents during downloading logs.

Will show in command message to let downloader knows what file we skips,
so downloader can try to download it manually if they prefer.

Change-Id: Ic87e1e2f1ef656b4d0615fa6fb68a1ed9067a956
---
 roles/local-log-download/templates/download-logs.sh.j2 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/roles/local-log-download/templates/download-logs.sh.j2 b/roles/local-log-download/templates/download-logs.sh.j2
index 40647fad1..53f124455 100644
--- a/roles/local-log-download/templates/download-logs.sh.j2
+++ b/roles/local-log-download/templates/download-logs.sh.j2
@@ -63,6 +63,7 @@ EOF
 }
 
 function save_file {
+    local exit_code=0
     local base_url="$1"
     local file="$2"
     local xtra_args="--compressed"
@@ -73,7 +74,10 @@ function save_file {
     if [[ "${file}" == *.xz ]]; then
         xtra_args=""
     fi
-    curl -s ${xtra_args} --create-dirs -o "${file}" "${base_url}${file}"
+    curl -s ${xtra_args} --create-dirs -o "${file}" "${base_url}${file}" || exit_code=$?
+    if [[ $exit_code -ne 0 ]]; then
+        log "Failed to download ${base_url}{$file}; skipping"
+    fi
    {#
     # Using --compressed we will send an Accept-Encoding: gzip header
     # and the data will come to us across the network compressed.