diff options
author | Zhao Lei <zhaolei@cn.fujitsu.com> | 2015-09-23 15:19:04 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-10-19 11:48:24 +0200 |
commit | 5627eee02b6e8b0a933ae88767e998923eb359f8 (patch) | |
tree | 0f21d4e09cbd14c1964058f886e693ae2a55dfc1 /tests | |
parent | 26bd9120614f6809783ea17a8bc010b767bf5008 (diff) |
btrfs-progs: tests: Move extract_image out of check_all_images for common use
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>
[minor reformatting and updates]
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/tests/common b/tests/common index 63b0d9f6..67d15588 100644 --- a/tests/common +++ b/tests/common @@ -62,51 +62,65 @@ check_image() run_check $TOP/btrfs check $image } -# Process all image dumps in a given directory, +# Extract a usable image from packed formats # - raw btrfs filesystem images, suffix .raw # - dtto compressed by XZ, suffix .raw.xz # - meta-dump images with suffix .img # - dtto compressed by XZ, suffix .img.xz +extract_image() +{ + local image + local cleanme + + image="$1" + 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 + + [ -f "$cleanme" ] && rm -f "$cleanme" + + echo "$image.restored" +} + +# Process all image dumps in a given directory check_all_images() { - dir=$1 + local dir + local extracted + + 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 + extracted=$(extract_image "$image") + check_image "$extracted" + rm -f "$extracted" done } |