#!/bin/sh

# This script shows that "tar u" using tar (GNU tar) 1.20 doesn't update
# an archive unless a folder's modification time is newer than the
# archive's modification time, even if the folder contains files that are
# not contained in the archive or the files' modification time is newer
# than the archive's modification time.

TEST_DIR=tar-test-run
if [ -d $TEST_DIR ]; then rm -rf $TEST_DIR; fi
mkdir $TEST_DIR
cd $TEST_DIR

echo "Creating files/file-1 and creating test.tar."
mkdir files
dd if=/dev/urandom of=files/file-1 count=1 bs=200000 > /dev/null 2>&1
tar cf test.tar files/
echo "test.tar contains file-1 as expected:"
tar tf test.tar

echo
echo "Creating files/file-2 and updating test.tar."
dd if=/dev/urandom of=files/file-2 count=1 bs=200000 > /dev/null 2>&1
tar uf test.tar files/
echo "test.tar should contain file-1 and file-2, but it doesn't:"
tar tf test.tar

echo
echo "Sleeping 2 seconds, touching file-2, and updating test.tar again."
sleep 2
touch files/file-2
tar uf test.tar files/
echo "test.tar should contain file-1 and file-2, but it still doesn't:"
tar tf test.tar

echo
echo "Touching files/ and updating test.tar a third time."
touch files/
tar uf test.tar files/
echo "Finally, test.tar now contains file-1 and file-2:"
tar tf test.tar

cd ..
exit

