You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2004/02/19 01:04:33 UTC

svn commit: rev 6738 - in incubator/spamassassin/trunk: lib/Mail/SpamAssassin t

Author: felicity
Date: Wed Feb 18 16:04:32 2004
New Revision: 6738

Modified:
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/BayesStoreDBM.pm
   incubator/spamassassin/trunk/t/bayesdbm.t
Log:
bug 3061: if bayes_learn_to_journal was set (sa-learn --norebuild does this too), and no bayes DB already existed, the learn would fail because tie_db_readonly() wouldn't create a db if it didn't already exist.  so we now failback to tieing r/w if r/o fails only if learn_to_journal is set.  cleaned up a bit of bayesdbm.t as well.

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	Wed Feb 18 16:04:32 2004
@@ -658,7 +658,10 @@
 
     my $ok;
     if ($self->{main}->{learn_to_journal}) {
-      $ok = $self->{store}->tie_db_readonly();
+      # If we're going to learn to journal, we'll try going r/o first...
+      # If that fails for some reason, let's try going r/w.  This happens
+      # if the DB doesn't exist yet.
+      $ok = $self->{store}->tie_db_readonly() || $self->{store}->tie_db_writable();
     } else {
       $ok = $self->{store}->tie_db_writable();
     }
@@ -778,7 +781,10 @@
 
     my $ok;
     if ($self->{main}->{learn_to_journal}) {
-      $ok = $self->{store}->tie_db_readonly();
+      # If we're going to learn to journal, we'll try going r/o first...
+      # If that fails for some reason, let's try going r/w.  This happens
+      # if the DB doesn't exist yet.
+      $ok = $self->{store}->tie_db_readonly() || $self->{store}->tie_db_writable();
     } else {
       $ok = $self->{store}->tie_db_writable();
     }

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/BayesStoreDBM.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/BayesStoreDBM.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/BayesStoreDBM.pm	Wed Feb 18 16:04:32 2004
@@ -136,7 +136,7 @@
   for my $ext (@DB_EXTENSIONS) { if (-f $path.'_toks'.$ext) { $found=1; last; } }
 
   if (!$found) {
-    dbg ("bayes: no dbs present, cannot scan: ${path}_toks");
+    dbg ("bayes: no dbs present, cannot tie DB R/O: ${path}_toks");
     return 0;
   }
 

Modified: incubator/spamassassin/trunk/t/bayesdbm.t
==============================================================================
--- incubator/spamassassin/trunk/t/bayesdbm.t	(original)
+++ incubator/spamassassin/trunk/t/bayesdbm.t	Wed Feb 18 16:04:32 2004
@@ -16,7 +16,7 @@
     unshift(@INC, '../blib/lib');
   }
 
-  plan tests => (HAS_DB_FILE ? 44 : 0);
+  plan tests => (HAS_DB_FILE ? 43 : 0);
 };
 
 exit unless HAS_DB_FILE;
@@ -48,13 +48,7 @@
 close(MAIL);
 ok($raw_message);
 
-my @msg;
-foreach my $line (split(/^/m,$raw_message)) {
-  $line =~ s/\r$//;
-  push(@msg, $line);
-}
-
-my $mail = $sa->parse( \@msg );
+my $mail = $sa->parse( $raw_message );
 
 ok($mail);
 
@@ -145,12 +139,6 @@
 
 $sa->init();
 
-# Slight cheat here, because when you learn only to journal it fails
-# to actually create the bayes_toks and bayes_seen files because we
-# are tieing read only, this will create the files for us and allow
-# things to continue
-ok($sa->{bayes_scanner}->{store}->tie_db_writable());
-
 ok(!-e 'log/user_state/bayes_journal');
 
 ok($sa->{bayes_scanner}->learn(1, $mail));
@@ -211,13 +199,7 @@
 
 close(MAIL);
 
-@msg = ();
-foreach my $line (split(/^/m,$raw_message)) {
-  $line =~ s/\r$//;
-  push(@msg, $line);
-}
-
-$mail = $sa->parse( \@msg );
+$mail = $sa->parse( $raw_message );
 
 $body = $sa->{bayes_scanner}->get_body_from_msg($mail);
 
@@ -242,13 +224,7 @@
 
 close(MAIL);
 
-@msg = ();
-foreach my $line (split(/^/m,$raw_message)) {
-  $line =~ s/\r$//;
-  push(@msg, $line);
-}
-
-$mail = $sa->parse( \@msg );
+$mail = $sa->parse( $raw_message );
 
 $body = $sa->{bayes_scanner}->get_body_from_msg($mail);