[Rt-commit] rt branch, 4.0/explicitly-set-file-temp-unlink, created. rt-4.0.7-58-gee2d7f0

Jim Brandt jbrandt at bestpractical.com
Wed Sep 19 14:19:46 EDT 2012


The branch, 4.0/explicitly-set-file-temp-unlink has been created
        at  ee2d7f0941e825a604e78457ad97fcbbd531eed0 (commit)

- Log -----------------------------------------------------------------
commit ee2d7f0941e825a604e78457ad97fcbbd531eed0
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Sep 19 14:02:53 2012 -0400

    Make File::Temp UNLINK setting explicit
    
    File::Temp has a default UNLINK setting of 1, which means it
    will delete temp files when the object goes out of scope. This
    change explicitly sets the UNLINK value to false when in
    debug mode, and leaves it true otherwise.
    
    File::Temp processes the unlink operation in its DESTROY method
    which means that in practice, the unlink code is typically not called
    when persistent processes like the RT standalone server or an
    apache process are killed and DESTROY is not called.
    However, for cases where the RT code exits normally or dies, email
    created with ($MailCommand, 'testfile') can be missing unexpectedly.
    Running rt-crontool, for example, with an action that sends mail shows
    this behavior.

diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 9270462..9ede707 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -396,7 +396,12 @@ sub SendEmail {
     my $mail_command = RT->Config->Get('MailCommand');
 
     if ($mail_command eq 'testfile' and not $Mail::Mailer::testfile::config{outfile}) {
-        $Mail::Mailer::testfile::config{outfile} = File::Temp->new;
+        # File::Temp default is to remove temp files (UNLINK => 1)
+        # This keeps files around when in debug mode (UNLINK => 0)
+        my $unlink = !( (RT->Config->Get('LogToScreen') eq 'debug')
+                        ||  (RT->Config->Get('LogToSyslog') eq 'debug') );
+
+        $Mail::Mailer::testfile::config{outfile} = File::Temp->new ( UNLINK => $unlink );
         $RT::Logger->info("Storing outgoing emails in $Mail::Mailer::testfile::config{outfile}");
     }
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list