#!/bin/sh
#
# clean log files
#
# Usage: clean-log [dir]
#

DIR=${1:-.}

#
# remove file with paranoia check
#

# remove main log file
if test -d ./log && test -f ./log/log.txt ; then
    rm ./log/log.txt
fi
if test -d ./log && test $(find ./log -type f -print | wc -l) = 0 ; then
    rmdir ./log
fi

# remove transaction log
for i in ./${DIR}/log.* ; do
 if test -d ${i} ; then
     (cd ${i} ; find . -maxdepth 1 -name "log-*-*-client" -exec rm "{}" ";")
     if [ $(find ${i} -type f -print | wc -l) = 0 ] ; then
	 rmdir ${i}
     fi
 fi
done

# end
