libisoburn/releng/test_hardlinks

139 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# ts 2011.06.27
# Test the correct handling of hardlinks by xorriso options
# -update_r and -hardlinks perform_update
export xorriso=xorriso
export image_file=/tmp/xorriso_hardlinks.iso
export on_disk=/tmp/xorriso_hardlinks_test_dir
export in_iso="$on_disk"
export copy_on_disk=/tmp/xorriso_hardlinks_copy_dir
export keep=0
export failure=0
export next_is_xorriso=0
clean_up() {
if test "$keep" = 1
then
dummy=dummy
echo "Kept test area because of option -keep" >&2
echo "$on_disk" "$copy_on_disk" "$image_file" >&2
else
rm -r "$on_disk" "$copy_on_disk" "$image_file"
fi
}
skip=0
for i in "$@"
do
if test "$next_is_xorriso" = 1
then
xorriso="$i"
next_is_xorriso=0
elif test "$skip" -gt 0
then
skip=$(expr $skip - 1)
elif test x"$i" = x"-rc"
then
# No configuration yet
skip=1
elif test x"$i" = x"-keep"
then
keep=1
elif test x"$i" = x"-clean_up"
then
keep=0
clean_up
exit 0
elif test x"$i" = x"-xorriso"
then
next_is_xorriso=1
else
echo "Usage: $0 [-rc FILE] [-keep] [-clean_up] [-xorriso PATH]" >&2
exit 2
fi
done
if test -e "$image_file"
then
echo "TEST ENVIRONMENT ERROR: $0 : Existing image_file target:" >&2
ls -ld "$image_file" >&2
exit 1
fi
if test -e "$on_disk"
then
echo "TEST ENVIRONMENT ERROR: $0 : Existing $on_disk target:" >&2
ls -ld "$on_disk" >&2
exit 1
fi
if test -e "$copy_on_disk"
then
echo "TEST ENVIRONMENT ERROR: $0 : Existing copy_on_disk target:" >&2
ls -ld "$copy_on_disk" >&2
exit 1
fi
# Set up $on_disk with several hardlinks
mkdir "$on_disk" || exit 1
echo test_content >"$on_disk"/file_1 || exit 1
echo test_content >"$on_disk"/file_2 || exit 1
ln "$on_disk"/file_1 "$on_disk"/file_1_link_a || exit 1
ln "$on_disk"/file_1 "$on_disk"/file_1_link_b || exit 1
ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1
ls -l "$on_disk"/*
# Produce simple image
"$xorriso" \
-for_backup \
-outdev "$image_file" \
-update_r "$on_disk" "$in_iso" \
-hardlinks perform_update
# Copy from image to temporary disk tree
"$xorriso" \
-for_backup \
-indev "$image_file" \
-osirrox on \
-find "$in_iso" -exec lsdl -- \
-extract "$in_iso" "$copy_on_disk"
# Compare original disk tree and temporary one
diff -r "$on_disk" "$copy_on_disk"
if test "$?" -ne 0
then
failure=1
fi
# Check for hardlinks being siblings
ls -l "$copy_on_disk"/*
x=$(echo $(ls -l "$copy_on_disk"/* | awk '{print $2}'))
expected="3 3 3 2 2"
if test x"$x" = x"$expected"
then
dummy=dummy
else
echo "WRONG: Link count of extracted files is not as expected." >&2
echo "Expected: $expected" >&2
echo "Got : $x" >&2
failure=1
fi
clean_up
# Report result
echo
echo "======== $(basename "$0") ========"
if test "$failure" = 1
then
echo 'FAILURE !!!'
else
echo "Success."
fi
echo