diff --git a/bin/cget.sh b/bin/cget.sh index ae34936..a30d344 100755 --- a/bin/cget.sh +++ b/bin/cget.sh @@ -201,6 +201,14 @@ location="$1" # Initialization ####################################################################### +# determine the log file +if $quiet_mode; then + log_file=/dev/null +else + log_file="$CACHE_DIR/cget_log.txt" + local_opts="$local_opts -L $log_file" +fi + # create temporary subdirectory /bin/mkdir "$tmp_dir" status_code=$? @@ -208,45 +216,36 @@ if [ $status_code -ne 0 ]; then echo "ERROR: $script_name failed to create tmp dir ($status_code) $tmp_dir" >&2 exit 2 fi +$verbose_mode && print_log_message "$script_name creating temp dir: $tmp_dir" "$log_file" # temporary file tmp_file="${tmp_dir}/http_resource_$$" -# determine the log file -if $quiet_mode; then - log_file=/dev/null -else - log_file="$CACHE_DIR/cget_log.txt" - local_opts="$local_opts -L $log_file" -fi - ####################################################################### # Main processing ####################################################################### -# The print_log_message function is defined in core_lib.sh +# Functions print_log_message and clean_up_and_exit defined in core_lib.sh +# Function conditional_get defined in http_tools.sh + print_log_message "$script_name requesting resource: $location" "$log_file" -# The conditional_get function is defined in http_tools.sh +# get the resource conditional_get $local_opts -d "$CACHE_DIR" -T "$tmp_dir" "$location" > "$tmp_file" status_code=$? if [ $status_code -ne 0 ]; then - # clean up and exit - /bin/rm -r "$tmp_dir" if [ $status_code -gt 1 ]; then - echo "ERROR: $script_name failed to get resource: $location" >&2 + echo "ERROR: $script_name failed to get resource ($status_code): $location" >&2 fi - exit $status_code + clean_up_and_exit -d "$tmp_dir" $status_code fi # output the resource /bin/cat "$tmp_file" status_code=$? -# clean up and exit -/bin/rm -r "$tmp_dir" if [ $status_code -ne 0 ]; then echo "ERROR: $script_name unable to cat output ($status_code)" >&2 - exit 3 + clean_up_and_exit -d "$tmp_dir" 3 fi exit 0