@@ -367,21 +367,17 @@ function download_to_cache() {
367
367
# check the remote location
368
368
local curl_info_json write_out
369
369
write_out=' {
370
- "http_code":%{http_code},
371
- "last_modified":"%header{Last-Modified}",
372
- "date":"%header{Date}",
373
- "content_type":"%{content_type}",
374
- "url":"%{url_effective}",
375
- "filename":"%{filename_effective}"
370
+ "json":%{json},
371
+ "header":%{header_json}
376
372
}'
377
373
curl_info_json=$( curl -sSLI -w " ${write_out} " " $1 " -o /dev/null)
378
374
379
375
local code time type url
380
- code=$( jq -r ' .http_code' <<< " ${curl_info_json}" )
381
- time=$( jq -r ' (.last_modified|select(length>1)) // . date' <<< " ${curl_info_json}" )
382
- type=$( jq -r ' .content_type' <<< " ${curl_info_json}" )
376
+ code=$( jq -r ' .json. http_code' <<< " ${curl_info_json}" )
377
+ time=$( jq -r ' (.header["last-modified"]|first) // (.header[" date"]|first) // empty ' <<< " ${curl_info_json}" )
378
+ type=$( jq -r ' .json. content_type' <<< " ${curl_info_json}" )
383
379
if [[ ${use_redirected_location} == " YES" ]]; then
384
- url=$( jq -r ' .url ' <<< " ${curl_info_json}" )
380
+ url=$( jq -r ' .json.url_effective ' <<< " ${curl_info_json}" )
385
381
else
386
382
url=$1
387
383
fi
@@ -400,11 +396,11 @@ function download_to_cache() {
400
396
curl -SL -w " ${write_out} " --no-clobber -o " ${cache_path} /data" " ${url} "
401
397
)
402
398
local filename
403
- code=$( jq -r ' .http_code' <<< " ${curl_info_json}" )
404
- time=$( jq -r ' (.last_modified|select(length>1)) // . date' <<< " ${curl_info_json}" )
405
- type=$( jq -r ' .content_type' <<< " ${curl_info_json}" )
406
- url=$( jq -r ' .url ' <<< " ${curl_info_json}" )
407
- filename=$( jq -r ' .filename ' <<< " ${curl_info_json}" )
399
+ code=$( jq -r ' .json. http_code' <<< " ${curl_info_json}" )
400
+ time=$( jq -r ' (.header["last-modified"]|first) // (.header[" date"]|first) // empty ' <<< " ${curl_info_json}" )
401
+ type=$( jq -r ' .json. content_type' <<< " ${curl_info_json}" )
402
+ url=$( jq -r ' .json.url_effective ' <<< " ${curl_info_json}" )
403
+ filename=$( jq -r ' .json.filename_effective ' <<< " ${curl_info_json}" )
408
404
[[ ${code} == 200 ]] || error_exit " Failed to download ${url} "
409
405
[[ " ${cache_path} /data" == " ${filename} " ]] || mv " ${filename} " " ${cache_path} /data"
410
406
# sha256.digest seems existing if expected digest is available. so, not creating it here.
0 commit comments