--- lib/Mail/SpamAssassin/DBBasedAddrList.pm.orig 2007-08-19 13:34:07.000000000 -0500 +++ lib/Mail/SpamAssassin/DBBasedAddrList.pm 2007-08-19 14:05:37.000000000 -0500 @@ -21,6 +21,8 @@ use warnings; use bytes; use Fcntl; +use File::Spec; +use File::Basename; use Mail::SpamAssassin::PersistentAddrList; use Mail::SpamAssassin::Util; @@ -74,6 +76,24 @@ $self->{locked_file} = $path; $self->{is_locked} = 1; ($mod1, $mod2) = ('R/W', O_RDWR | O_CREAT); + + # This is a work around for bugs in berkley db 4.2 + # on 4.2 having the __db.[DBNAME] file will cause an loop that will never finish + # on 4.3+ the loop will timeout after 301 open attempts, but we will still be unable to open + # the database. This work around solves both problems. + if ($dbm_module eq 'DB_File') { + my $parentdir = File::Basename::dirname($path); + + my $db_tmpfile = File::Spec->catfile($parentdir,'__db.' . File::Basename::basename($path)); + dbg("auto-whitelist: Berkley DB bug work-around: cleaning tmp file $db_tmpfile"); + + if ( -e $db_tmpfile ) { + if ( ! unlink($db_tmpfile) ) { + die 'auto-whitelist: cannot remove ' . $db_tmpfile . ': ' . $! . "\n"; + } + } + } + } else { $self->{is_locked} = 0; --- lib/Mail/SpamAssassin/BayesStore/DBM.pm.orig 2007-08-19 13:38:36.000000000 -0500 +++ lib/Mail/SpamAssassin/BayesStore/DBM.pm 2007-08-19 14:11:05.000000000 -0500 @@ -276,6 +278,22 @@ my $umask = umask 0; foreach my $dbname (@DBNAMES) { + + # This is a work around for bugs in berkley db 4.2 + # on 4.2 having the __db.[DBNAME] file will cause an loop that will never finish + # on 4.3+ the loop will timeout after 301 open attempts, but we will still be unable to open + # the database. This work around solves both problems. + if ( $self->DBM_MODULE eq 'DB_File' ) { + my $db_tmpfile = File::Spec->catfile($parentdir,'__db.' . File::Basename::basename($path) . '_' . $dbname); + dbg("bayes: Berkley DB bug work-around: cleaning tmp file $db_tmpfile"); + if ( -e $db_tmpfile) { + if ( ! unlink($db_tmpfile) ) { + warn 'bayes: cannot remove ' . $db_tmpfile . ': ' . $! . "\n"; + return 0; + } + } + } + my $name = $path.'_'.$dbname; my $db_var = 'db_'.$dbname; dbg("bayes: tie-ing to DB file R/W $name");