#!/bin/sh
# Copyright 2011  Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Helper script for cmdtest tests: verify restored data.

set -e

summain -r "$DATADIR/data" > "$DATADIR/data.summain"
summain -r "$DATADIR/restored/$DATADIR/data" > "$DATADIR/restored.summain"

# Timestamps are whole seconds with sftp, so we need to mangle the
# summain output to remove sub-second timestamps.
if [ "$OBNAM_TEST_SFTP_ROOT" = yes ]
then
    "$SRCDIR/sed-in-place" '/^Mtime:/s/\.[[:digit:]]\+ / /' \
        "$DATADIR/data.summain" \
        "$DATADIR/restored.summain"
fi

# Allow caller to mangle further.
if [ "x$1" != x ]
then
    for x in "$DATADIR/data.summain" "$DATADIR/restored.summain"
    do
        awk "$1" "$x" > "$x.new"
        mv "$x.new" "$x"
    done
fi

diff -u "$DATADIR/data.summain" "$DATADIR/restored.summain"

