Skip to content

Commit

Permalink
Trim redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Scavo committed May 2, 2017
1 parent 0c0b471 commit cdbba53
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions lib/http_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ conditional_get () {
echo "ERROR: $FUNCNAME: directory does not exist: $tmp_dir" >&2
return 2
fi
$verbose_mode && print_log_message -D "$FUNCNAME using temporary directory $tmp_dir"
print_log_message -D "$FUNCNAME using temporary directory $tmp_dir"

# a cache directory is required
if [ -z "$cache_dir" ]; then
Expand All @@ -174,7 +174,7 @@ conditional_get () {
echo "ERROR: $FUNCNAME: directory does not exist: $cache_dir" >&2
return 2
fi
$verbose_mode && print_log_message -D "$FUNCNAME using cache directory $cache_dir"
print_log_message -D "$FUNCNAME using cache directory $cache_dir"

# determine the URL location
shift $(( OPTIND - 1 ))
Expand All @@ -187,7 +187,7 @@ conditional_get () {
echo "ERROR: $FUNCNAME: empty URL argument" >&2
return 2
fi
$verbose_mode && print_log_message -D "$FUNCNAME using location $location"
print_log_message -D "$FUNCNAME using location $location"

#######################################################################
#
Expand All @@ -212,10 +212,8 @@ conditional_get () {
cached_header_file="$cache_dir/${hash}_headers"
cached_content_file="$cache_dir/${hash}_content"

if $verbose_mode; then
print_log_message -D "$FUNCNAME using cached header file: $cached_header_file"
print_log_message -D "$FUNCNAME using cached content file: $cached_content_file"
fi
print_log_message -D "$FUNCNAME using cached header file: $cached_header_file"
print_log_message -D "$FUNCNAME using cached content file: $cached_content_file"

# check if the resource is cached
if [ -f "$cached_header_file" ] && [ -f "$cached_content_file" ]; then
Expand Down Expand Up @@ -254,11 +252,9 @@ conditional_get () {
tmp_content_file="$tmp_dir/${FUNCNAME}_curl_content"
tmp_stderr_file="$tmp_dir/${FUNCNAME}_curl_stderr"

if $verbose_mode; then
print_log_message -D "$FUNCNAME using temp header file: ${tmp_header_file}"
print_log_message -D "$FUNCNAME using temp content file: ${tmp_content_file}"
print_log_message -D "$FUNCNAME using temp stderr file: ${tmp_stderr_file}"
fi
print_log_message -D "$FUNCNAME using temp header file: ${tmp_header_file}"
print_log_message -D "$FUNCNAME using temp content file: ${tmp_content_file}"
print_log_message -D "$FUNCNAME using temp stderr file: ${tmp_stderr_file}"

#######################################################################
#
Expand Down Expand Up @@ -311,7 +307,7 @@ conditional_get () {

# invoke curl
cmd="/usr/bin/curl $curl_opts $location"
$verbose_mode && print_log_message -D "$FUNCNAME issuing curl command: $cmd"
print_log_message -D "$FUNCNAME issuing curl command: $cmd"
eval $cmd
exit_code=$?
if [ $exit_code -ne 0 ]; then
Expand Down Expand Up @@ -364,13 +360,11 @@ conditional_get () {
print_log_message -W "$FUNCNAME: Content-Length response header missing"
fi

if $verbose_mode; then
print_log_message -D "$FUNCNAME downloaded ${actual_content_length} bytes"
if $do_conditional_get; then
print_log_message -D "$FUNCNAME refreshing cache files"
else
print_log_message -D "$FUNCNAME initializing cache files"
fi
print_log_message -D "$FUNCNAME downloaded ${actual_content_length} bytes"
if $do_conditional_get; then
print_log_message -D "$FUNCNAME refreshing cache files"
else
print_log_message -D "$FUNCNAME initializing cache files"
fi

# update the cache; maintain cache integrity at all times
Expand All @@ -397,7 +391,7 @@ conditional_get () {
return 1
fi

$verbose_mode && print_log_message -D "$FUNCNAME downloaded 0 bytes (cache is up-to-date)"
print_log_message -D "$FUNCNAME downloaded 0 bytes (cache is up-to-date)"
else
print_log_message -E "$FUNCNAME failed with HTTP response code $response_code"
return 9
Expand Down

0 comments on commit cdbba53

Please sign in to comment.