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 2006/03/16 06:01:24 UTC

svn commit: r386260 - /spamassassin/trunk/lib/Mail/SpamAssassin.pm

Author: felicity
Date: Wed Mar 15 21:01:23 2006
New Revision: 386260

URL: http://svn.apache.org/viewcvs?rev=386260&view=rev
Log:
bug 4827: in first_existing_path(), return undef if none of the paths are found instead of using the last path in the list

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin.pm?rev=386260&r1=386259&r2=386260&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin.pm Wed Mar 15 21:01:23 2006
@@ -1333,9 +1333,16 @@
     if ($siterules) {
       $self->{config_text} .= $self->read_pre($siterules, 'site rules pre files');
     }
+    else {
+      warn "config: could not find site rules directory\n";
+    }
+
     if ($sysrules) {
       $self->{config_text} .= $self->read_pre($sysrules, 'sys rules pre files');
     }
+    else {
+      warn "config: could not find sys rules directory\n";
+    }
 
     $fname = $sysrules;
     if ($fname) {
@@ -1363,6 +1370,9 @@
           warn "config: failed to create default user preference file $fname\n";
         }
       }
+      else {
+	warn "config: could not find userprefs file\n";
+      }
 
       $self->{config_text} .= $self->read_cf ($fname, 'user prefs file');
     }
@@ -1470,14 +1480,20 @@
 
   $fname ||= $self->first_existing_path (@default_userstate_dir);
 
-  if (defined $fname && !$self->{dont_copy_prefs}) {
-    dbg("config: using \"$fname\" for user state dir");
-  }
+  if (defined $fname) {
+    if (!$self->{dont_copy_prefs}) {
+      dbg("config: using \"$fname\" for user state dir");
+    }
 
-  if (!-d $fname) {
-    # not being able to create the *dir* is not worth a warning at all times
-    eval { mkpath($fname, 0, 0700) } or dbg("config: mkdir $fname failed: $@ $!\n");
+    if (!-d $fname) {
+      # not being able to create the *dir* is not worth a warning at all times
+      eval { mkpath($fname, 0, 0700) } or dbg("config: mkdir $fname failed: $@ $!\n");
+    }
+  }
+  else {
+    warn "config: can not determine userstate dir\n";
   }
+
   $fname;
 }
 
@@ -1485,7 +1501,7 @@
 
 Find a rule-support file, such as C<languages> or C<triplets.txt>,
 in the system-wide rules directory, and return its full path if
-it exists.
+it exists, or undef if it doesn't exist.
 
 (This API was added in SpamAssassin 3.1.1.)
 
@@ -1533,7 +1549,7 @@
     # copy in the default one for later editing
     my $defprefs = $self->first_existing_path (@Mail::SpamAssassin::default_prefs_path);
 
-    if (open (IN, "<$defprefs")) {
+    if (defined $defprefs && open (IN, "<$defprefs")) {
       $fname = Mail::SpamAssassin::Util::untaint_file_path($fname);
       if (open (OUT, ">$fname")) {
         while (<IN>) {
@@ -1556,9 +1572,12 @@
         warn "config: cannot write to $fname: $!\n";
       }
     }
-    else {
+    elsif (defined $defprefs) {
       warn "config: cannot open $defprefs: $!\n";
     }
+    else {
+      warn "config: can not determine default prefs path\n";
+    }
   }
 
   return(0);
@@ -1601,7 +1620,7 @@
   $path =~ s/__local_state_dir__/$self->{LOCAL_STATE_DIR} || ''/ges;
   $path =~ s/__def_rules_dir__/$self->{DEF_RULES_DIR} || ''/ges;
   $path =~ s{__prefix__}{$self->{PREFIX} || $Config{prefix} || '/usr'}ges;
-  $path =~ s{__userstate__}{$self->get_and_create_userstate_dir()}ges;
+  $path =~ s{__userstate__}{$self->get_and_create_userstate_dir() || ''}ges;
   $path =~ s/__version__/${VERSION}/gs;
   $path =~ s/^\~([^\/]*)/$self->expand_name($1)/es;
 
@@ -1617,7 +1636,7 @@
     $path = $self->sed_path ($p);
     if (defined $path && -e $path) { return $path; }
   }
-  $path;
+  return;
 }
 
 ###########################################################################