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 2005/05/14 01:52:10 UTC
svn commit: r170109 - /spamassassin/trunk/lib/Mail/SpamAssassin.pm
/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
Author: felicity
Date: Fri May 13 16:52:09 2005
New Revision: 170109
URL: http://svn.apache.org/viewcvs?rev=170109&view=rev
Log:
bug 4330: Conf::clone() was not restoring code references which made things like all eval rules stop functioning. initial attempt to revert to a 'overwrite' mode instead of a 'make a new object' setup.
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin.pm?rev=170109&r1=170108&r2=170109&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin.pm Fri May 13 16:52:09 2005
@@ -1710,19 +1710,11 @@
# than having this class know all about that class' internals...
if (defined $source) {
dbg ("config: copying current conf from backup");
- $self->{conf} = $source->{obj}->clone();
}
else {
dbg ("config: copying current conf to backup");
- if ($dest->{obj}) {
- # delete any existing copies first, to ensure that
- # circular references are cleaned up
- $dest->{obj}->finish();
- }
- $dest->{obj} = $self->{conf}->clone();
}
-
- return 1;
+ return $self->{conf}->clone($source, $dest);
}
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm?rev=170109&r1=170108&r2=170109&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm Fri May 13 16:52:09 2005
@@ -128,17 +128,6 @@
$MISSING_REQUIRED_VALUE = -998;
$INVALID_VALUE = -999;
-# keys that should not be copied in ->clone()
-my @NON_COPIED_KEYS = qw(
- main eval_plugins plugins_loaded registered_commands sed_path_cache parser
- scoreset scores
-);
-
-# keys that should can be copied using a ->clone() method, in ->clone()
-my @CLONABLE_KEYS = qw(
- internal_networks trusted_networks
-);
-
# set to "1" by the test suite code, to record regression tests
# $Mail::SpamAssassin::Conf::COLLECT_REGRESSION_TESTS = 1;
@@ -3027,41 +3016,51 @@
###########################################################################
sub clone {
- my ($self) = @_;
- my $dest = Mail::SpamAssassin::Conf->new($self->{main});
+ my ($self, $source, $dest) = @_;
+
+ unless (defined $source) {
+ $source = $self;
+ }
+ unless (defined $dest) {
+ $dest = $self;
+ }
+
+ # keys that should not be copied in ->clone()
+ my @NON_COPIED_KEYS = qw(
+ main eval_plugins plugins_loaded registered_commands sed_path_cache parser
+ scoreset scores
+ );
+
+ # keys that should can be copied using a ->clone() method, in ->clone()
+ my @CLONABLE_KEYS = qw(
+ internal_networks trusted_networks
+ );
+
my %done = ();
# special cases. first, skip anything that cannot be changed
# by users, and the stuff we take care of here
- foreach my $var (@NON_COPIED_KEYS, @CLONABLE_KEYS) {
- $done{$var} = undef;
- }
-
foreach my $key (@CLONABLE_KEYS) {
- $dest->{$key} = $self->{$key}->clone();
+ $dest->{$key} = $source->{$key}->clone();
+ $done{$key} = undef;
}
- # scoresets
- for my $i (0 .. 3) {
- %{$dest->{scoreset}->[$i]} = %{$self->{scoreset}->[$i]};
+ foreach my $var (@NON_COPIED_KEYS) {
+ $done{$var} = undef;
}
- # deal with $conf->{scores}, it needs to be a reference into the scoreset
- # hash array dealy
- $dest->{scores} = $dest->{scoreset}->[$dest->{scoreset_current}];
-
- # ensure we don't copy the path cache from the master
- delete $dest->{sed_path_cache};
-
# and now, copy over all the rest -- the less complex cases.
- while(my($k,$v) = each %{$self}) {
+ while(my($k,$v) = each %{$source}) {
next if exists $done{$k}; # we handled it above
my $i = ref($v);
# Not a reference, or a scalar? Just copy the value over.
- if (!$i || $i eq 'SCALAR') {
+ if ($i eq '') {
$dest->{$k} = $v;
}
+ elsif ($i eq 'SCALAR') {
+ $dest->{$k} = $$v;
+ }
elsif ($i eq 'ARRAY') {
@{$dest->{$k}} = @{$v};
}
@@ -3073,7 +3072,22 @@
warn "config: dup unknown type $k, $i\n";
}
}
- return $dest;
+
+ # scoresets
+ delete $dest->{scoreset};
+ for my $i (0 .. 3) {
+ %{$dest->{scoreset}->[$i]} = %{$source->{scoreset}->[$i]};
+ }
+
+ # deal with $conf->{scores}, it needs to be a reference into the scoreset
+ # hash array dealy. Do it at the end since scoreset_current isn't set
+ # otherwise.
+ $dest->{scores} = $dest->{scoreset}->[$dest->{scoreset_current}];
+
+ # ensure we don't copy the path cache from the master
+ delete $dest->{sed_path_cache};
+
+ return 1;
}
###########################################################################