From dfa237b2eeb9099478a9345819f0937e14d4a538 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 19 Oct 2011 13:09:34 +0200 Subject: [PATCH] Bug #867: Image size is not accurate for empty files. --- src/image_mad/remotes/fs/fsrc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/image_mad/remotes/fs/fsrc b/src/image_mad/remotes/fs/fsrc index 423f27e26b..0f49049d1f 100644 --- a/src/image_mad/remotes/fs/fsrc +++ b/src/image_mad/remotes/fs/fsrc @@ -41,14 +41,19 @@ echo "$IMAGE_REPOSITORY_PATH/`echo $CANONICAL_MD5 | cut -d ' ' -f1`" } function fs_du { + SIZE="" -SIZE=`$DU -m $1 2>/dev/null` + QEMU_IMG=`command -v qemu-img` -if [ $? -ne 0 ]; then - SIZE=0 -else - SIZE=`echo $SIZE | cut -f1 -d' '` -fi + if [ "$?" = "0" ]; then + SIZE=$($QEMU_IMG info $1|awk '/^virtual size:/{print substr($4,2)}') + fi -echo "$SIZE" + if [ -z "$SIZE" ]; then + SIZE=$(stat -c %s $1) + fi + + SIZE=$(($SIZE/1048576)) + + echo "$SIZE" }