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 2007/04/20 21:10:58 UTC

svn commit: r530889 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Message.pm t/mimeparse.t

Author: jm
Date: Fri Apr 20 12:10:57 2007
New Revision: 530889

URL: http://svn.apache.org/viewvc?view=rev&rev=530889
Log:
bug 5430: deleting the temporary file while keeping it open is a POSIX idiom, unsupported on Win32.  replace with an unlink when the Message object is finish()ed or freed

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
    spamassassin/trunk/t/mimeparse.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm?view=diff&rev=530889&r1=530888&r2=530889
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Message.pm Fri Apr 20 12:10:57 2007
@@ -108,6 +108,7 @@
 
   my $self = $class->SUPER::new({normalize=>$normalize});
 
+  $self->{tmpfiles} =           [];
   $self->{pristine_headers} =	'';
   $self->{pristine_body} =	'';
   $self->{mime_boundary_state} = {};
@@ -523,6 +524,12 @@
   # Clean ourself up
   $self->finish_metadata();
 
+  # delete temporary files
+  if ($self->{'tmpfiles'}) {
+    unlink @{$self->{'tmpfiles'}};
+    delete $self->{'tmpfiles'};
+  }
+
   # These will only be in the root Message node
   delete $self->{'mime_boundary_state'};
   delete $self->{'mbox_sep'};
@@ -555,6 +562,15 @@
   }
 }
 
+# also use a DESTROY method, just to ensure (as much as possible) that
+# temporary files are deleted even if the finish() method is omitted
+sub DESTROY {
+  my $self = shift;
+  if ($self->{'tmpfiles'}) {
+    unlink @{$self->{'tmpfiles'}};
+  }
+}
+
 # ---------------------------------------------------------------------------
 
 =item receive_date()
@@ -861,12 +877,10 @@
     ($filepath, $msg->{'raw'}) = Mail::SpamAssassin::Util::secure_tmpfile();
 
     if ($filepath) {
-      # The temp file was created, let's try to delete it now
-      if (!unlink $filepath) {
-        # We couldn't delete the file, so abort trying to make the temp file.
-        close($msg->{'raw'});
-	unlink $filepath; # try again with the file closed
-      }
+      # The temp file was created, add it to the list of pending deletions
+      # we cannot just delete immediately in the POSIX idiom, as this is
+      # unportable (to win32 at least)
+      push @{$self->{tmpfiles}}, $filepath;
       $msg->{'raw'}->print(@{$body});
     }
   }

Modified: spamassassin/trunk/t/mimeparse.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/mimeparse.t?view=diff&rev=530889&r1=530888&r2=530889
==============================================================================
--- spamassassin/trunk/t/mimeparse.t (original)
+++ spamassassin/trunk/t/mimeparse.t Fri Apr 20 12:10:57 2007
@@ -7,6 +7,7 @@
 
   if (-e 'test_dir') {            # running from test directory, not ..
     unshift(@INC, '../blib/lib');
+    unshift(@INC, '../lib');
   }
 }
 



Re: svn commit: r530889 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Message.pm t/mimeparse.t

Posted by Sidney Markowitz <si...@sidney.com>.
Wow, you're blasting through the Win32 build problems, Justin. My nmake
test is still runnig, but I can see that much of the errors are gone.

I do see a use of system("mv ...") at the end of t/mkrules.t which
doesn't work in CMD.EXE, but so far it is looking very good.

 -- sidney