From: William Morgan Date: Tue, 8 Jan 2008 18:42:58 +0000 (-0800) Subject: bugfix: attachment tempfile deletion X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=385c5e85852e1a2c81ce3672e90fa1d021f7bd3f;p=sup bugfix: attachment tempfile deletion attachment temp files (used for Attachment#view!) now use (a monkey-patched) Tempfile, so they should be deleted upon program exit or gc or however it works. --- diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb index fbd193c..7d09740 100644 --- a/lib/sup/message-chunks.rb +++ b/lib/sup/message-chunks.rb @@ -1,4 +1,4 @@ -require 'tmpdir' +require 'tempfile' ## Here we define all the "chunks" that a message is parsed ## into. Chunks are used by ThreadViewMode to render a message. Chunks @@ -31,6 +31,14 @@ require 'tmpdir' ## included as quoted text during a reply. Text, Quotes, and mime-parsed ## attachments are quotable; Signatures are not. +## monkey-patch time: make temp files have the right extension +class Tempfile + def make_tmpname basename, n + sprintf '%d-%d-%s', $$, n, basename + end +end + + module Redwood module Chunk class Attachment @@ -103,13 +111,7 @@ EOS end def write_to_disk - file = - if @filename - File.open File.join(Dir::tmpdir, @filename), "w" - else - Tempfile.new "redwood.attachment" - end - + file = Tempfile.new(@filename || "sup-attachment") file.print @raw_content file.close file.path diff --git a/lib/sup/message.rb b/lib/sup/message.rb index 53ab2a6..65aebd5 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -1,4 +1,3 @@ -require 'tempfile' require 'time' require 'iconv'