You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2012/12/18 16:05:37 UTC
svn commit: r1423467 -
/spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/Redis.pm
Author: hege
Date: Tue Dec 18 15:05:37 2012
New Revision: 1423467
URL: http://svn.apache.org/viewvc?rev=1423467&view=rev
Log:
Bug 6881: Bayes storage module for Redis should be optional
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/Redis.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/Redis.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/Redis.pm?rev=1423467&r1=1423466&r2=1423467&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/Redis.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/Redis.pm Tue Dec 18 15:05:37 2012
@@ -59,7 +59,6 @@ use re 'taint';
use Errno qw(EBADF);
use Mail::SpamAssassin::Util qw(untaint_var);
use Mail::SpamAssassin::Timeout;
-use Redis;
BEGIN {
eval { require Digest::SHA; import Digest::SHA qw(sha1); 1 }
@@ -73,6 +72,8 @@ use vars qw( @ISA );
@ISA = qw( Mail::SpamAssassin::BayesStore );
+use constant HAS_REDIS => eval { require Redis; };
+
=head1 METHODS
=head2 new
@@ -91,6 +92,10 @@ sub new {
$class = ref($class) || $class;
my $self = $class->SUPER::new(@_);
+ unless (HAS_REDIS) {
+ dbg("bayes: unable to connect to database: DBI module not available: $!");
+ }
+
push @{$self->{redis_conf}}, 'encoding' => undef;
foreach (split(';', $self->{bayes}->{conf}->{bayes_sql_dsn})) {
@@ -138,6 +143,8 @@ working.
sub tie_db_readonly {
my($self) = @_;
+ return 0 unless (HAS_REDIS);
+
my $result = $self->{is_really_open} || $self->_open_db();
$self->{is_writable} = 0 if $result;
@@ -158,6 +165,8 @@ begin using the database immediately.
sub tie_db_writable {
my($self) = @_;
+ return 0 unless (HAS_REDIS);
+
my $result = $self->{is_really_open} || $self->_open_db();
$self->{is_writable} = 1 if $result;