]> wimlib.net Git - wimlib/blobdiff - tests/test-imagex-capture_and_apply
do_overlay(): Do overlays recursively
[wimlib] / tests / test-imagex-capture_and_apply
index 0a53aee0bf3c93887273b35d2c2f66c95b0d9d73..5de3b0e20de5e35555977a83cb72ad5e1c07fefb 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 # Test capturing and applying a WIM image in the normal (non-NTFS) capture mode
 #
@@ -9,42 +9,15 @@
 # Also, test if the capture configuration file works correctly.
 
 set -e
-srcdir=${srcdir:-.}
-srcdir=`realpath $srcdir`
 cd tests
+srcdir="${srcdir:-.}/.."
+srcdir="$(cd $srcdir; pwd)"
+. "$srcdir/tests/tests-common.sh"
 
-imagex() {
-       echo "imagex $@"
-       ../imagex "$@" > /dev/null
-}
-
-imagex_info() {
-       echo "imagex info $@"
-       ../imagex info "$@"
-}
-
-init() {
-       mkdir in.dir out.dir
-}
-
-cleanup() {
-       rm -rf in.dir out.dir test*.wim test*.swm
-}
-
-error() {
-       echo "****************************************************************"
-       echo "                         Test failure                           "
-       echo $*
-       echo "****************************************************************"
-       exit 1
-}
-
-wim_ctype() {
-       ../imagex info $1 | grep Compression | awk '{print $2}'
-}
+TEST_SUBDIR=tmpdir_test-imagex-capture_and_apply
 
 do_tree_cmp() {
-       if ! ./tree-cmp in.dir out.dir; then
+       if ! ../tree-cmp in.dir out.dir; then
                if [ -x /usr/bin/tree ]; then
                        echo "Dumping tree of applied image"
                        echo "(Note: compression type was $ctype)"
@@ -57,7 +30,7 @@ do_tree_cmp() {
 
 image_name=0
 do_test() {
-       for ctype in None LZX XPRESS; do
+       for ctype in None XPRESS LZX; do
 
                # Can we capture the WIM, apply it, and get the same result?
                cd in.dir
@@ -66,7 +39,7 @@ do_test() {
                if [ -x /usr/bin/tree -a "$ctype" = "None" ]; then
                        tree in.dir --inodes -F -s --noreport
                fi
-               if ! imagex capture in.dir test.wim --compress=$ctype; then
+               if ! imagex capture in.dir test.wim --compress=$ctype --norpfix; then
                        error "Failed to capture directory tree into a WIM"
                fi
                if ! imagex apply test.wim 1 out.dir; then
@@ -80,7 +53,7 @@ do_test() {
 
                # Can we split the WIM, apply the split WIM, join the split WIM,
                # and apply the joined WIM, and get the same results every time?
-               if ! imagex split test.wim test.swm 0.01M; then
+               if ! imagex split test.wim test.swm 0.01; then
                        error "Failed to split WIM"
                fi
                if ! imagex apply test.swm 1 out.dir --ref "test*.swm" ; then
@@ -114,19 +87,25 @@ do_test() {
        done
 }
 
-msg() {
+__msg() {
        echo "--------------------------------------------------------------------"
-       echo "Testing image capture and application of directory containing $1"
+       echo $1
        echo "--------------------------------------------------------------------"
 }
 
-cleanup
-init
+msg() {
+       __msg "Testing image capture and application of directory containing $1"
+}
 
-. common_tests.sh
+default_cleanup
+mkdir $TEST_SUBDIR
+cd $TEST_SUBDIR
+mkdir in.dir out.dir
+
+. $srcdir/tests/common_tests.sh
 
 # Make sure exclusion list works
-msg "Testing default capture configuration file"
+__msg "Testing default capture configuration file"
 touch in.dir/hiberfil.sys
 mkdir -p "in.dir/System Volume Information/subdir"
 imagex capture in.dir test.wim
@@ -134,10 +113,120 @@ imagex apply test.wim out.dir
 if [ -e out.dir/hiberfil.sys -o -e "out.dir/System Volume Information" ]; then
        error "Files were not excluded from capture as expected"
 fi
-rm -rf out.dir/* in.dir/*
 
-cleanup
+# Make sure reparse point fixups are working as expected
+__msg "Testing --rpfix"
+rm -r in.dir out.dir
+mkdir in.dir
+ln -s $PWD/in.dir          in.dir/absrootlink
+ln -s $PWD/in.dir////      in.dir/absrootlinkslashes
+ln -s /___NONEXISTENT___   in.dir/absnonexistent
+ln -s /usr/bin/env         in.dir/absoutoftree
+ln -s file                 in.dir/relalink
+ln -s $PWD/in.dir/file     in.dir/abslink
+ln -s $PWD/in.dir/file///  in.dir/abslinkslashes
+imagex capture --rpfix in.dir test.wim
+imagex apply --norpfix test.wim out.dir
+if [[ `readlink out.dir/absrootlink` != "/" ]] ||
+   [[ `readlink out.dir/absrootlinkslashes` != "////" ]]; then
+       error "imagex capture --rpfix failed to fix absolute link to capture root"
+fi
+
+if [[ -e out.dir/absnonexistent ]] ||
+   [[ -e out.dir/absoutoftree ]]; then
+       error "imagex capture --rpfix failed to exclude out of tree absolute links"
+fi
+if [[ `readlink out.dir/relalink` != "file" ]]; then
+       error "imagex capture --rpfix failed to capture relative symlink"
+fi
+if [[ `readlink out.dir/abslink` != "/file" ]] ||
+   [[ `readlink out.dir/abslinkslashes` != "/file///" ]]; then
+       error "imagex capture --rpfix did fix absolute link properly"
+fi
+rm -rf out.dir
+
+imagex apply test.wim out.dir
+if [[ $(get_inode_number $(readlink out.dir/absrootlink)) != \
+       $(get_inode_number out.dir) ]];
+then
+       error "imagex apply failed to apply fixed absolute symlinks"
+fi
+
+# Make sure source list mode is working as expected
+__msg "Testing source list capture mode"
+rm -rf in.dir out.dir
+mkdir in.dir
+echo 1 > in.dir/1
+ln in.dir/1 in.dir/1link
+echo 5 > 5
+mkdir otherdir
+cp $srcdir/src/add_image.c otherdir
+cat > srclist << EOF
+in.dir /
+5      /5
+otherdir /otherdir
+EOF
+imagex capture srclist --source-list test.wim
+imagex apply test.wim out.dir
+if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
+      ! -d out.dir/otherdir ]]; then
+       error "source list capture failed to work as expected"
+fi
+
+# Still testing source list capture: add quoted name, and try overlay
+rm -rf out.dir
+cat > srclist << EOF
+in.dir /
+5      /5
+otherdir /otherdir
+ "overlay dir 1"               'otherdir'      
+ "overlay dir 2"               'otherdir'  
+EOF
+mkdir "overlay dir 1"
+mkdir "overlay dir 2"
+echo A > "overlay dir 1"/A
+echo B > "overlay dir 2"/B
+imagex capture srclist --source-list test.wim
+imagex apply test.wim out.dir
+if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
+      ! -f out.dir/otherdir/A || ! -f out.dir/otherdir/B ]]; then
+       error "source list capture (with quoted names and basic overlay) failed to work as expected"
+fi
+
+# Try deep overlay
+rm -rf in.dir out.dir "overlay dir 1" "overlay dir 2"
+mkdir -p in.dir.1/subdir/subdir2 in.dir.2/subdir/subdir2
+cat > srclist << EOF
+in.dir.1       /
+in.dir.2       /
+EOF
+echo 1 > in.dir.1/subdir/1
+echo 2 > in.dir.2/subdir/2
+echo 3 > in.dir.1/subdir/subdir2/3
+echo 4 > in.dir.2/subdir/subdir2/4
+imagex capture srclist --source-list test.wim
+imagex apply test.wim out.dir
+if [[ ! -f out.dir/subdir/1 || ! -f out.dir/subdir/2 ||        \
+       ! -f out.dir/subdir/subdir2/3 || ! -f out.dir/subdir/subdir2/4 ]]; then
+       error "source list capture (with deep overlay) failed to work as expected"
+fi
+
+# Try bad overlay
+__msg "Testing bad overlay (errors expected)"
+rm -rf out.dir
+echo 5 > 5
+cat > srclist << EOF
+in.dir.1       /
+in.dir.2       /
+5              /subdir
+EOF
+if imagex capture srclist --source-list test.wim; then
+       error "unexpected success in bad overlay with --source-list!"
+fi
 
 echo "**********************************************************"
 echo "          imagex capture/apply tests passed               "
 echo "**********************************************************"
+
+cd ..
+default_cleanup