You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by pa...@apache.org on 2005/12/19 17:25:17 UTC

svn commit: r357719 - in /spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore: DBM.pm SDBM.pm

Author: parker
Date: Mon Dec 19 08:25:13 2005
New Revision: 357719

URL: http://svn.apache.org/viewcvs?rev=357719&view=rev
Log:
Bug 4670

Added a few helper methods to unlinking and renaming database file with
multiple extensions.

Modified:
    spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/DBM.pm
    spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/SDBM.pm

Modified: spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/DBM.pm
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/DBM.pm?rev=357719&r1=357718&r2=357719&view=diff
==============================================================================
--- spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/DBM.pm (original)
+++ spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/DBM.pm Mon Dec 19 08:25:13 2005
@@ -286,7 +286,8 @@
 
   # set our cache to what version DB we're using
   $self->{db_version} = ($self->get_storage_variables())[6];
-  dbg("bayes: found bayes db version ".$self->{db_version});
+  # don't bother printing this if the db was not found since it is bogus anyway
+  dbg("bayes: found bayes db version ".$self->{db_version}) if ($found);
 
   # figure out if we can read the current DB and if we need to do a
   # DB version update and do it if necessary if either has a problem,
@@ -1604,7 +1605,7 @@
 	  (oct ($main->{conf}->{bayes_file_mode}) & 0666)) {
     dbg("bayes: failed to tie temp seen db: $!");
     untie %new_toks;
-    unlink $tmptoksdbname;
+    $self->_unlink_file($tmptoksdbname);
     $self->untie_db();
     umask $umask;
     return 0;
@@ -1636,8 +1637,8 @@
     dbg("bayes: database version must be the first line in the backup file, correct and re-run");
     untie %new_toks;
     untie %new_seen;
-    unlink $tmptoksdbname;
-    unlink $tmpseendbname;
+    $self->_unlink_file($tmptoksdbname);
+    $self->_unlink_file($tmpseendbname);
     $self->untie_db();
     return 0;
   }
@@ -1646,8 +1647,8 @@
     warn("bayes: database version $db_version is unsupported, must be version 2 or 3");
     untie %new_toks;
     untie %new_seen;
-    unlink $tmptoksdbname;
-    unlink $tmpseendbname;
+    $self->_unlink_file($tmptoksdbname);
+    $self->_unlink_file($tmpseendbname);
     $self->untie_db();
     return 0;
   }
@@ -1768,8 +1769,8 @@
 
     untie %new_toks;
     untie %new_seen;
-    unlink $tmptoksdbname;
-    unlink $tmpseendbname;
+    $self->_unlink_file($tmptoksdbname);
+    $self->_unlink_file($tmpseendbname);
     $self->untie_db();
     return 0;
   }
@@ -1800,11 +1801,11 @@
   # database files.  If we are able to copy one and not the other then it
   # will leave the database in an inconsistent state.  Since this is an
   # edge case, and they're trying to replace the DB anyway we should be ok.
-  unless (rename($tmptoksdbname, $toksdbname)) {
+  unless ($self->_rename_file($tmptoksdbname, $toksdbname)) {
     dbg("bayes: error while renaming $tmptoksdbname to $toksdbname: $!");
     return 0;
   }
-  unless (rename($tmpseendbname, $seendbname)) {
+  unless ($self->_rename_file($tmpseendbname, $seendbname)) {
     dbg("bayes: error while renaming $tmpseendbname to $seendbname: $!");
     dbg("bayes: database now in inconsistent state");
     return 0;
@@ -1816,7 +1817,6 @@
   return 1;
 }
 
-
 ###########################################################################
 
 # token marshalling format for db_toks.
@@ -1899,6 +1899,20 @@
 }
 
 ###########################################################################
+
+sub _unlink_file {
+  my ($self, $filename) = @_;
+
+  unlink $filename;
+}
+
+sub _rename_file {
+  my ($self, $sourcefilename, $targetfilename) = @_;
+
+  return 0 unless (rename($sourcefilename, $targetfilename));
+
+  return 1;
+}
 
 sub sa_die { Mail::SpamAssassin::sa_die(@_); }
 

Modified: spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/SDBM.pm
URL: http://svn.apache.org/viewcvs/spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/SDBM.pm?rev=357719&r1=357718&r2=357719&view=diff
==============================================================================
--- spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/SDBM.pm (original)
+++ spamassassin/branches/3.1/lib/Mail/SpamAssassin/BayesStore/SDBM.pm Mon Dec 19 08:25:13 2005
@@ -47,6 +47,23 @@
   return ('.pag', '.dir');
 }
 
+sub _unlink_file {
+  my ($self, $filename) = @_;
+
+  for my $ext ($self->DB_EXTENSIONS) {
+    unlink $filename . $ext;
+  }
+}
+
+sub _rename_file {
+  my ($self, $sourcefilename, $targetfilename) = @_;
+
+  for my $ext ($self->DB_EXTENSIONS) {
+    return 0 unless (rename($sourcefilename . $ext, $targetfilename . $ext));
+  }
+  return 1;
+}
+
 # this is called directly from sa-learn(1).
 sub perform_upgrade {