#! /bin/sh
#
# Test for updating documents in an index.
#
LOG=`pwd`/test-log
TARGET=`./select-data`
TMPDATA=`pwd`/tmp-data

if test ! -d idx7; then
    mkdir idx7
else
    rm -f idx7/NMZ.*
fi

# Copy docments.
if test -d tmp-data; then
    rm -rf tmp-data
fi
cp -rp $TARGET tmp-data

# Simple indexing.
cd ../scripts 
./mknmz -O ../tests/idx7 $TMPDATA >> $LOG
test "$?" != "0" && exit 1  # error if not success

prevdocnum=`perl -lne 'print $1 if /^files (\d+)/' ../tests/idx7/NMZ.status`

# Update some documents. Add `xyzzy' to each document.
cd $TMPDATA
find . -type f -print | egrep '(plain|mail)\.txt$' | \
    perl -nle 'system "echo xyzzy >> $_"'
cd ../

# Update the index.
cd ../scripts 
./mknmz --update=../tests/idx7 >> $LOG
test "$?" != "0" && exit 1  # error if not success

postdocnum=`perl -lne 'print $1 if /^files (\d+)/' ../tests/idx7/NMZ.status`

echo "predocnum:" $prevdocnum, "postdocnum:" $postdocnum >> $LOG
test $prevdocnum != $postdocnum && exit 1  # error if prev != post
exit 0
