From 99b622a936c0b6f5b6283f3bcdca3bd7d0628e29 Mon Sep 17 00:00:00 2001 From: Ryan Hsu Date: Wed, 5 Mar 2014 15:35:49 -0800 Subject: [PATCH] Refactor vmdk upload code A syntax error is hit when trying to upload a flat vmdk file that is accompanied by a descriptor file. The code block that handles this has some unneeded characters that cause the error. Also, an else-block has been removed so that we can remove an extra indent. Change-Id: Iaf5c914e09da6831eeeec141228b39554a1e2216 Closes-bug: #1288471 --- functions | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/functions b/functions index ab8319b0ce..1d30922916 100644 --- a/functions +++ b/functions @@ -163,38 +163,37 @@ function upload_image { if [[ ${IMAGE_NAME: -5} != "-flat" ]]; then warn $LINENO "Expected filename suffix: '-flat'."` `" Filename provided: ${IMAGE_NAME}" - else - descriptor_fname="${IMAGE_NAME:0:${#IMAGE_NAME} - 5}.vmdk" - path_len=`expr ${#image_url} - ${#IMAGE_FNAME}` - flat_path="${image_url:0:$path_len}" - descriptor_url=$flat_path$descriptor_fname - warn $LINENO "$descriptor_data_pair_msg"` - `" Attempt to retrieve the descriptor *.vmdk: $descriptor_url" - if [[ $flat_path != file* ]]; then - if [[ ! -f $FILES/$descriptor_fname || \ - "$(stat -c "%s" $FILES/$descriptor_fname)" = "0" ]]; then - wget -c $descriptor_url -O $FILES/$descriptor_fname - if [[ $? -ne 0 ]]; then - warn $LINENO "Descriptor not found $descriptor_url" - descriptor_found=false - fi - fi - descriptor_url="$FILES/$descriptor_fname" - else - descriptor_url=$(echo $descriptor_url | sed "s/^file:\/\///g") - if [[ ! -f $descriptor_url || \ - "$(stat -c "%s" $descriptor_url)" == "0" ]]; then + fi + + descriptor_fname="${IMAGE_NAME:0:${#IMAGE_NAME} - 5}.vmdk" + path_len=`expr ${#image_url} - ${#IMAGE_FNAME}` + flat_path="${image_url:0:$path_len}" + descriptor_url=$flat_path$descriptor_fname + warn $LINENO "$descriptor_data_pair_msg"` + `" Attempt to retrieve the descriptor *.vmdk: $descriptor_url" + if [[ $flat_path != file* ]]; then + if [[ ! -f $FILES/$descriptor_fname || \ + "$(stat -c "%s" $FILES/$descriptor_fname)" = "0" ]]; then + wget -c $descriptor_url -O $FILES/$descriptor_fname + if [[ $? -ne 0 ]]; then warn $LINENO "Descriptor not found $descriptor_url" descriptor_found=false fi fi - if $descriptor_found; then - vmdk_adapter_type="$(head -25 $descriptor_url |"` - `" { grep -a -F -m 1 'ddb.adapterType =' $descriptor_url || true; })" - vmdk_adapter_type="${vmdk_adapter_type#*\"}" - vmdk_adapter_type="${vmdk_adapter_type%?}" + descriptor_url="$FILES/$descriptor_fname" + else + descriptor_url=$(echo $descriptor_url | sed "s/^file:\/\///g") + if [[ ! -f $descriptor_url || \ + "$(stat -c "%s" $descriptor_url)" == "0" ]]; then + warn $LINENO "Descriptor not found $descriptor_url" + descriptor_found=false fi fi + if $descriptor_found; then + vmdk_adapter_type="$(head -25 $descriptor_url | { grep -a -F -m 1 'ddb.adapterType =' $descriptor_url || true; })" + vmdk_adapter_type="${vmdk_adapter_type#*\"}" + vmdk_adapter_type="${vmdk_adapter_type%?}" + fi vmdk_disktype="preallocated" else vmdk_disktype="preallocated"