Fix download scripts to handle empty lines

Fixing download and saving scripts to be able to ignore empty or 00D
ending lines in lists

Issue-ID: OOM-1818

Change-Id: I55ef1dfbea628f8c1d4b19745536e629a2dbe0c9
Signed-off-by: Tomáš Levora <t.levora@partner.samsung.com>
diff --git a/build/creating_data/save-docker-images.sh b/build/creating_data/save-docker-images.sh
index 4c76455..0a72d15 100755
--- a/build/creating_data/save-docker-images.sh
+++ b/build/creating_data/save-docker-images.sh
@@ -19,15 +19,10 @@
 #   COPYRIGHT NOTICE ENDS HERE
 
 
-# boilerplate
-RELATIVE_PATH=../ # relative path from this script to 'common-functions.sh'
-if [ "$IS_COMMON_FUNCTIONS_SOURCED" != YES ] ; then
-    SCRIPT_DIR=$(dirname "${0}")
-    LOCAL_PATH=$(readlink -f "$SCRIPT_DIR")
-    . "${LOCAL_PATH}"/"${RELATIVE_PATH}"/common-functions.sh
-fi
+# Load common-functions library
+. $(dirname ${0})/../common-functions.sh
 
-LIST="${1}"
+LIST_FILE="${1}"
 IMG_DIR="${2}"
 
 if [[ -z "$IMG_DIR" ]]; then
@@ -56,11 +51,9 @@
 
 echo "Save all images"
 line=1
-lines=$(wc -l ${LIST})
-while read -r image; do
+lines=$(clean_list "$LIST_FILE" | wc -l)
+for image in $(clean_list "$LIST_FILE"); do
     echo "== pkg #$line of $lines =="
-
     save_image "${image}"
     line=$((line+1))
-
-done < "${LIST}"
+done
\ No newline at end of file