You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2005/12/21 02:40:35 UTC

svn commit: r358174 - /spamassassin/trunk/sa-update.raw

Author: jm
Date: Tue Dec 20 17:40:34 2005
New Revision: 358174

URL: http://svn.apache.org/viewcvs?rev=358174&view=rev
Log:
sa-update should use commandline --updatedir if specified; should override default channels if --channel is set, not add to it; should keep track of cwd so that relative paths (nearly) work; and should debug-log failure page contents

Modified:
    spamassassin/trunk/sa-update.raw

Modified: spamassassin/trunk/sa-update.raw
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/sa-update.raw?rev=358174&r1=358173&r2=358174&view=diff
==============================================================================
--- spamassassin/trunk/sa-update.raw (original)
+++ spamassassin/trunk/sa-update.raw Tue Dec 20 17:40:34 2005
@@ -30,6 +30,7 @@
 use File::Path;
 use Getopt::Long;
 use Pod::Usage;
+use Cwd;
 use strict;
 use warnings;
 
@@ -168,7 +169,7 @@
 });
 
 # $opt{'updatedir'} ||= $SA->first_existing_path(@Mail::SpamAssassin::site_rules_path);
-$opt{'updatedir'} = $SA->sed_path('__local_state_dir__/spamassassin/__version__');
+$opt{'updatedir'} ||= $SA->sed_path('__local_state_dir__/spamassassin/__version__');
 
 dbg("generic: sa-update version $VERSION");
 dbg("generic: using update directory: $opt{'updatedir'}");
@@ -219,7 +220,7 @@
 
 # Deal with channel-related options
 if (defined $opt{'channel'}) {
-  push(@channels, @{$opt{'channel'}});
+  @channels = @{$opt{'channel'}};
 }
 if (defined $opt{'channelfile'}) {
   unless (open(CHAN, $opt{'channelfile'})) {
@@ -227,6 +228,7 @@
   }
 
   dbg("channel: reading in channelfile ".$opt{'channelfile'});
+  @channels = ();
   while(my $chan = <CHAN>) {
     $chan = lc $chan;
     dbg("channel: adding $chan");
@@ -547,6 +549,7 @@
   die "fatal: couldn't create Archive::Tar object!\n" unless $tar;
 
   # make sure we're doing the work in the update directory
+  my $oldwd = getcwd();
   unless (chdir $UPDDir) {
     warn "error: can't chdir into $UPDDir: $!\n";
     dbg("channel: chdir failed, channel failed");
@@ -555,7 +558,10 @@
   }
 
   dbg("channel: extracting archive");
-  unless ($tar->extract()) {
+  my $ret = ($tar->extract());
+  chdir $oldwd;     # chdir back so relative paths on --updatedir work
+
+  unless ($ret) {
     close($tfh);
     warn "error: couldn't extract the tar archive!\n";
     dbg("channel: archive extraction failed, channel failed");
@@ -582,6 +588,7 @@
     next unless ($file =~ /\.cf$/);
     dbg("channel: adding $file");
     print CF "include $UPDDir/$file\n";
+    # TODO: this fails for relative paths, e.g. "--updatedir ./updtest"
   }
   closedir(DIR);
   close(CF);
@@ -643,7 +650,13 @@
     return $response->content;
   }
 
-  dbg("http: request failed: " . $response->status_line);
+  # include the text in the debug output; it's useful in some cases,
+  # e.g. proxies that require authentication, diagnosing fascist
+  # filtering false positives, etc.
+  my $text = $response->content;
+  $text ||= "(no body)";
+  $text =~ s/\s+/ /gs;
+  dbg("http: request failed: " . $response->status_line.": ".$text);
   return;
 }