~ubuntu-branches/ubuntu/lucid/spamassassin/lucid-proposed

« back to all changes in this revision

Viewing changes to lib/Mail/SpamAssassin/BayesStore/DBM.pm

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville, Ubuntu Merge-o-Matic, Laurent Bigonville
  • Date: 2006-07-31 15:40:08 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060731154008-j37ulp5pgfkddegw
Tags: 3.1.3-1ubuntu1
[ Ubuntu Merge-o-Matic ]
* Merge from debian unstable.

[ Laurent Bigonville ]
* fix debian/control.
* drop debian/patches/40_fix_dns_issue.

Show diffs side-by-side

added added

removed removed

Lines of Context:
286
286
 
287
287
  # set our cache to what version DB we're using
288
288
  $self->{db_version} = ($self->get_storage_variables())[6];
289
 
  dbg("bayes: found bayes db version ".$self->{db_version});
 
289
  # don't bother printing this if the db was not found since it is bogus anyway
 
290
  dbg("bayes: found bayes db version ".$self->{db_version}) if ($found);
290
291
 
291
292
  # figure out if we can read the current DB and if we need to do a
292
293
  # DB version update and do it if necessary if either has a problem,
1604
1605
          (oct ($main->{conf}->{bayes_file_mode}) & 0666)) {
1605
1606
    dbg("bayes: failed to tie temp seen db: $!");
1606
1607
    untie %new_toks;
1607
 
    unlink $tmptoksdbname;
 
1608
    $self->_unlink_file($tmptoksdbname);
1608
1609
    $self->untie_db();
1609
1610
    umask $umask;
1610
1611
    return 0;
1636
1637
    dbg("bayes: database version must be the first line in the backup file, correct and re-run");
1637
1638
    untie %new_toks;
1638
1639
    untie %new_seen;
1639
 
    unlink $tmptoksdbname;
1640
 
    unlink $tmpseendbname;
 
1640
    $self->_unlink_file($tmptoksdbname);
 
1641
    $self->_unlink_file($tmpseendbname);
1641
1642
    $self->untie_db();
1642
1643
    return 0;
1643
1644
  }
1646
1647
    warn("bayes: database version $db_version is unsupported, must be version 2 or 3");
1647
1648
    untie %new_toks;
1648
1649
    untie %new_seen;
1649
 
    unlink $tmptoksdbname;
1650
 
    unlink $tmpseendbname;
 
1650
    $self->_unlink_file($tmptoksdbname);
 
1651
    $self->_unlink_file($tmpseendbname);
1651
1652
    $self->untie_db();
1652
1653
    return 0;
1653
1654
  }
1768
1769
 
1769
1770
    untie %new_toks;
1770
1771
    untie %new_seen;
1771
 
    unlink $tmptoksdbname;
1772
 
    unlink $tmpseendbname;
 
1772
    $self->_unlink_file($tmptoksdbname);
 
1773
    $self->_unlink_file($tmpseendbname);
1773
1774
    $self->untie_db();
1774
1775
    return 0;
1775
1776
  }
1800
1801
  # database files.  If we are able to copy one and not the other then it
1801
1802
  # will leave the database in an inconsistent state.  Since this is an
1802
1803
  # edge case, and they're trying to replace the DB anyway we should be ok.
1803
 
  unless (rename($tmptoksdbname, $toksdbname)) {
 
1804
  unless ($self->_rename_file($tmptoksdbname, $toksdbname)) {
1804
1805
    dbg("bayes: error while renaming $tmptoksdbname to $toksdbname: $!");
1805
1806
    return 0;
1806
1807
  }
1807
 
  unless (rename($tmpseendbname, $seendbname)) {
 
1808
  unless ($self->_rename_file($tmpseendbname, $seendbname)) {
1808
1809
    dbg("bayes: error while renaming $tmpseendbname to $seendbname: $!");
1809
1810
    dbg("bayes: database now in inconsistent state");
1810
1811
    return 0;
1816
1817
  return 1;
1817
1818
}
1818
1819
 
1819
 
 
1820
1820
###########################################################################
1821
1821
 
1822
1822
# token marshalling format for db_toks.
1900
1900
 
1901
1901
###########################################################################
1902
1902
 
 
1903
sub _unlink_file {
 
1904
  my ($self, $filename) = @_;
 
1905
 
 
1906
  unlink $filename;
 
1907
}
 
1908
 
 
1909
sub _rename_file {
 
1910
  my ($self, $sourcefilename, $targetfilename) = @_;
 
1911
 
 
1912
  return 0 unless (rename($sourcefilename, $targetfilename));
 
1913
 
 
1914
  return 1;
 
1915
}
 
1916
 
1903
1917
sub sa_die { Mail::SpamAssassin::sa_die(@_); }
1904
1918
 
1905
1919
1;