linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Lei <zhaolei@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Zhao Lei <zhaolei@cn.fujitsu.com>
Subject: [PATCH v2 1/3] btrfs-progs: tests: Move extract_image out of check_all_images for common use
Date: Wed, 23 Sep 2015 15:19:04 +0800	[thread overview]
Message-ID: <79b70366a2679adbc039ba11b92d874460fb6d0c.1442992715.git.zhaolei@cn.fujitsu.com> (raw)
In-Reply-To: <cover.1442992715.git.zhaolei@cn.fujitsu.com>

Move code for extract image file to a function from check_all_images()
for common use, so caller can use this function to extrace single
image file.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 tests/common | 76 ++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/tests/common b/tests/common
index 63b0d9f..320c4dd 100644
--- a/tests/common
+++ b/tests/common
@@ -62,6 +62,44 @@ check_image()
 	run_check $TOP/btrfs check $image
 }
 
+extract_image()
+{
+	local image="$1"
+
+	local cleanme=
+	case "$image" in
+	*.img)
+		rm -f $image.restored
+		: ;;
+	*.img.xz)
+		xz --decompress --keep "$image" || \
+			_fail "failed to decompress image $image" >&2
+		image=${image%%.xz}
+		rm -f $image.restored
+		cleanme=$image
+		;;
+	*.raw)
+		cp --sparse=auto $image $image.restored
+		;;
+	*.raw.xz)
+		xz --decompress --keep "$image" || \
+			_fail "failed to decompress image $image" >&2
+		image=${image%%.xz}
+		mv "$image" "$image".restored
+		;;
+	esac
+
+	if ! [ -f $image.restored ]; then
+		echo "restoring image $(basename $image)" >> $RESULTS
+		$TOP/btrfs-image -r $image $image.restored || \
+			_fail "failed to restore image $image" >&2
+	fi
+
+	[[ "$cleanme" ]] && rm -f "$cleanme"
+
+	echo "$image.restored"
+}
+
 # Process all image dumps in a given directory,
 # - raw btrfs filesystem images, suffix .raw
 # - dtto compressed by XZ, suffix .raw.xz
@@ -69,44 +107,16 @@ check_image()
 # - dtto compressed by XZ, suffix .img.xz
 check_all_images()
 {
-	dir=$1
+	local dir=$1
 	for image in $(find $dir \( -iname '*.img' -o	\
 				-iname '*.img.xz' -o 	\
 				-iname '*.raw' -o 	\
 				-iname '*.raw.xz' \) | sort)
 	do
-		cleanme=
-		case "$image" in
-		*.img)
-			rm -f $image.restored
-			: ;;
-		*.img.xz)
-			xz --decompress --keep "$image" || \
-				_fail "failed to decompress image $image"
-			image=${image%%.xz}
-			rm -f $image.restored
-			cleanme=$image
-			;;
-		*.raw)
-			cp --sparse=auto $image $image.restored
-			;;
-		*.raw.xz)
-			xz --decompress --keep "$image" || \
-				_fail "failed to decompress image $image"
-			image=${image%%.xz}
-			mv "$image" "$image".restored
-			;;
-		esac
-
-		if ! [ -f $image.restored ]; then
-			echo "restoring image $(basename $image)" >> $RESULTS
-			$TOP/btrfs-image -r $image $image.restored || \
-				_fail "failed to restore image $image"
-		fi
-
-		check_image $image.restored
-
-		rm -f $image.restored $cleanme
+		local extracted
+		extracted=$(extract_image "$image")
+		check_image "$extracted"
+		rm -f "$extracted"
 	done
 }
 
-- 
1.8.5.1


  reply	other threads:[~2015-09-23  7:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-23  7:19 [PATCH v2 0/3] btrfs-progs: tests: Move extract_image out of check_all_images for common use Zhao Lei
2015-09-23  7:19 ` Zhao Lei [this message]
2015-09-23  7:19 ` [PATCH v2 2/3] btrfs-progs: tests: Introduce fsck-tests/018-leaf-across-stripes Zhao Lei
2015-09-23 12:24   ` David Sterba
2015-09-23  7:19 ` [PATCH v2 3/3] btrfs-progs: tests: Introduce misc-tests/008-leaf-across-stripes Zhao Lei
2015-09-23 12:46 ` [PATCH v2 0/3] btrfs-progs: tests: Move extract_image out of check_all_images for common use David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=79b70366a2679adbc039ba11b92d874460fb6d0c.1442992715.git.zhaolei@cn.fujitsu.com \
    --to=zhaolei@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).