Re: new bf_compact
David Relson <[email protected]>
| Newsgroups | gmane.mail.bogofilter.devel |
|---|---|
| Organization | Osage Software Systems, Inc. |
| Message-ID | <[email protected]> |
On Sun, 08 May 2005 20:02:03 +0200 Matthias Andree wrote: > David Relson <[email protected]> writes: > > > The current version is attached. > > Nope. Remember to reset the MIME type to something other than > application/octet-stream, for instance text/x-sh. > > If it's the same as in CVS, don't bother. :-) I'm resending it with the thought that others might want to see/test it. _______________________________________________ Bogofilter-dev mailing list [email protected] http://www.bogofilter.org/mailman/listinfo/bogofilter-dev
bf_compact
(text/plain, 1.7 KB)
#!/bin/sh
# bf_compact source_dir [wordlist_name...]
#
# use to compact wordlist.db
# replaces original directory with new one
# renames original directory with '.old' extension
# $Id: bf_compact,v 1.24 2005/05/08 17:14:49 relson Exp $
set -e # die on errors
if [ -z "$1" ] ; then
echo 'usage: bf_compact source_dir [wordlist_name...]'
exit 1
fi
# extract home directory
BOGOHOME="$1"
shift
if [ ! -d "$BOGOHOME" ] ; then
echo $BOGOHOME must be a directory, not a file
exit 1
fi
# strip trailing slashes
while true; do
case "$BOGOHOME" in
*/) BOGOHOME=${BOGOHOME%/} ;;
*) break ;;
esac
done
# find wordlists
if [ -n "$1" ] ; then
FILES="$@"
else
DIR=`bogofilter -QQ | grep ^bogofilter_dir | awk '{print $3}'`
if [ "$BOGOHOME" != "$DIR" ] ; then
FILES=`ls "$BOGOHOME"/*.db`
else
FILES=`bogofilter -QQ | grep ^wordlist | cut -f3 -d,`
fi
fi
TEMP="bf_compact.$$"
mkdir "$TEMP" || {
echo "Cannot create directory $TEMP. Abort."
exit 1
}
# copy Berkeley DB configuration if present
if test -f "$BOGOHOME"/DB_CONFIG ; then
cp -p "$BOGOHOME"/DB_CONFIG "$TEMP"/
fi
# determine transactions
if test "`find "$BOGOHOME/" -name "log.??????????" -print`" != "" ; then
TXN=yes
fi
# reload files
for FILE in $FILES ; do
NAME=`basename $FILE`
bogoutil -d $FILE | bogoutil --db-transaction=no -l $TEMP/$NAME
done
if [ -n "$TXN" ] ; then
#create database environment files
bogofilter -e -C -d $TEMP --db-transaction=yes < /dev/null
fi
# remove $BOGOHOME.old so we don't move the new backup *into* it
# rather than renaming the backup to it.
rm -rf "$BOGOHOME.old"
mv "$BOGOHOME" "$BOGOHOME.old"
mv $TEMP "$BOGOHOME"