From b740c50c7625162a6ba4499a7dfbc7450deac3eb Mon Sep 17 00:00:00 2001 From: iberezovskiy Date: Tue, 13 May 2014 17:57:35 +0400 Subject: [PATCH] Rename old image file instead of rewrite it If we have the old image file with same name as new image file we shouldn't rewrite it, just need to rename old. Uses date number in old image name. Fixes TODO in lib/common-functions Change-Id: Ica58a0f4435217912bddf950322299d2ed2889f3 --- lib/common-functions | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/common-functions b/lib/common-functions index f3f73c74..00b55e83 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -43,6 +43,12 @@ function mk_build_dir () { } function finish_image () { + if [ -f $1 ]; then + old_image="${1%.*}"-$(date +%Y.%m.%d-%H.%M.%S).${1##*.} + echo "Old image is found. Renaming it to $old_image" + mv "$1" "$old_image" + fi + mv $TMP_IMAGE_PATH $1 cleanup_dirs # All done! @@ -51,10 +57,10 @@ function finish_image () { } function save_image () { - # TODO: this really should rename the old file if [ -f $1 ] ; then - echo "Old Image file Found REMOVING" - rm -f $1 + old_image="${1%.*}"-$(date +%Y.%m.%d-%H.%M.%S).${1##*.} + echo "Old image is found. Renaming it to $old_image" + mv "$1" "$old_image" fi cp $TMP_IMAGE_PATH $1