]> arthur.barton.de Git - bup.git/blobdiff - t/test.sh
Add support for "bup restore --exclude-rx <pattern> ...".
[bup.git] / t / test.sh
index 644a07ba6a23e3838d0928e9d7de2a33c71acffd..58c9cca25e153bc831cdf7232d4784a4f25e9f2d 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -354,49 +354,58 @@ d/
 f"
 
 WVSTART "exclude"
-D=exclude.tmp
-force-delete $D
-mkdir $D
-export BUP_DIR="$D/.bup"
-WVPASS bup init
-touch $D/a
-WVPASS bup random 128k >$D/b
-mkdir $D/d $D/d/e
-WVPASS bup random 512 >$D/f
-WVPASS bup index -ux --exclude $D/d $D
-bup save -n exclude $D
-WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
+(
+    set -e -o pipefail
+    D=exclude.tmp
+    force-delete $D
+    mkdir $D
+    export BUP_DIR="$D/.bup"
+    WVPASS bup init
+    touch $D/a
+    WVPASS bup random 128k >$D/b
+    mkdir $D/d $D/d/e
+    WVPASS bup random 512 >$D/f
+    WVPASS bup random 512 >$D/j
+    WVPASS bup index -ux --exclude $D/d --exclude $D/j $D
+    bup save -n exclude $D
+    WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
 b
 f"
-mkdir $D/g $D/h
-WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h $D
-bup save -n exclude $D
-WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
+    mkdir $D/g $D/h
+    WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h \
+        --exclude $TOP/$D/j $D
+    bup save -n exclude $D
+    WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
 b
 f"
+) || WVFAIL
 
 WVSTART "exclude-from"
-D=exclude-fromdir.tmp
-EXCLUDE_FILE=exclude-from.tmp
-echo "$D/d 
+(
+    set -e -o pipefail
+    D=exclude-fromdir.tmp
+    EXCLUDE_FILE=exclude-from.tmp
+    echo "$D/d 
  $TOP/$D/g
-$D/h" > $EXCLUDE_FILE
-force-delete $D
-mkdir $D
-export BUP_DIR="$D/.bup"
-WVPASS bup init
-touch $D/a
-WVPASS bup random 128k >$D/b
-mkdir $D/d $D/d/e
-WVPASS bup random 512 >$D/f
-mkdir $D/g $D/h
-WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
-bup save -n exclude-from $D
-WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
+$D/h
+$D/i" > $EXCLUDE_FILE
+    force-delete $D
+    mkdir $D
+    export BUP_DIR="$D/.bup"
+    WVPASS bup init
+    touch $D/a
+    WVPASS bup random 128k >$D/b
+    mkdir $D/d $D/d/e
+    WVPASS bup random 512 >$D/f
+    mkdir $D/g $D/h
+    WVPASS bup random 128k > $D/i
+    WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
+    bup save -n exclude-from $D
+    WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
 b
 f"
-rm $EXCLUDE_FILE
-
+    rm $EXCLUDE_FILE
+) || WVFAIL
 
 WVSTART "save (no index)"
 (
@@ -648,7 +657,8 @@ mkdir $D
 WVPASS bup init
 WVPASS bup index $TOP/Documentation
 WVPASS bup save -n compression -9 --strip $TOP/Documentation
-WVPASSEQ "$(bup ls compression/latest/ | sort)" "$(ls $TOP/Documentation | sort)"
+WVPASSEQ "$(bup ls compression/latest/ | sort)" \
+         "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
 COMPRESSION_9_SIZE=$(du -k -s $D | cut -f1)
 
 WVPASS [ "$COMPRESSION_9_SIZE" -lt "$COMPRESSION_0_SIZE" ]
@@ -681,7 +691,6 @@ WVSTART "save disjoint top-level directories"
     WVPASSEQ "$(bup ls -a src/latest)" "$(echo -e "$top_dir/\ntmp/" | sort)"
 ) || WVFAIL
 
-
 WVSTART "clear-index"
 D=clear-index.tmp
 export BUP_DIR="$TOP/$D/.bup"
@@ -701,3 +710,174 @@ bup index -u $TOP/$D
 WVPASSEQ "$(bup index -p)" "$D/bar
 $D/
 ./"
+
+# bup index --exclude-rx ...
+(
+    set -e
+    export BUP_DIR="$TOP/buptest.tmp"
+    D=bupdata.tmp
+
+    WVSTART "index --exclude-rx '^/foo' (root anchor)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    mkdir $D/sub1
+    mkdir $D/sub2
+    touch $D/sub1/a
+    touch $D/sub2/b
+    WVPASS bup index -u $D --exclude-rx "^$(pwd)/$D/sub1/"
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./sub2
+./sub2/b"
+
+    WVSTART "index --exclude-rx '/foo$' (non-dir, tail anchor)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    touch $D/foo
+    mkdir $D/sub
+    mkdir $D/sub/foo
+    touch $D/sub/foo/a
+    WVPASS bup index -u $D --exclude-rx '/foo$'
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./sub
+./sub/foo
+./sub/foo/a"
+
+    WVSTART "index --exclude-rx '/foo/$' (dir, tail anchor)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    touch $D/foo
+    mkdir $D/sub
+    mkdir $D/sub/foo
+    touch $D/sub/foo/a
+    WVPASS bup index -u $D --exclude-rx '/foo/$'
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./foo
+./sub"
+
+    WVSTART "index --exclude-rx '/foo/.' (dir content)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    touch $D/foo
+    mkdir $D/sub
+    mkdir $D/sub/foo
+    touch $D/sub/foo/a
+    WVPASS bup index -u $D --exclude-rx '/foo/.'
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./foo
+./sub
+./sub/foo"
+) || WVFAIL
+
+
+# bup restore --exclude-rx ...
+(
+    set -e
+    export BUP_DIR="$TOP/buptest.tmp"
+    D=bupdata.tmp
+
+    WVSTART "restore --exclude-rx '^/foo' (root anchor)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    mkdir $D/sub1
+    mkdir $D/sub2
+    touch $D/sub1/a
+    touch $D/sub2/b
+    WVPASS bup index -u $D
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp --exclude-rx "^/sub1/" /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./sub2
+./sub2/b"
+
+    WVSTART "restore --exclude-rx '/foo$' (non-dir, tail anchor)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    touch $D/foo
+    mkdir $D/sub
+    mkdir $D/sub/foo
+    touch $D/sub/foo/a
+    WVPASS bup index -u $D
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp --exclude-rx '/foo$' /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./sub
+./sub/foo
+./sub/foo/a"
+
+    WVSTART "restore --exclude-rx '/foo/$' (dir, tail anchor)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    touch $D/foo
+    mkdir $D/sub
+    mkdir $D/sub/foo
+    touch $D/sub/foo/a
+    WVPASS bup index -u $D
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp --exclude-rx '/foo/$' /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./foo
+./sub"
+
+    WVSTART "restore --exclude-rx '/foo/.' (dir content)"
+    rm -rf "$D" "$BUP_DIR" buprestore.tmp
+    WVPASS bup init
+    mkdir $D
+    touch $D/a
+    touch $D/b
+    touch $D/foo
+    mkdir $D/sub
+    mkdir $D/sub/foo
+    touch $D/sub/foo/a
+    WVPASS bup index -u $D
+    bup save --strip -n bupdir $D
+    bup restore -C buprestore.tmp --exclude-rx '/foo/.' /bupdir/latest/
+    WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
+./a
+./b
+./foo
+./sub
+./sub/foo"
+) || WVFAIL