]> git.cworth.org Git - sup/commitdiff
bugfix: attachment tempfile deletion
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Tue, 8 Jan 2008 18:42:58 +0000 (10:42 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Tue, 8 Jan 2008 19:47:23 +0000 (11:47 -0800)
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.

lib/sup/message-chunks.rb
lib/sup/message.rb

index fbd193ccd033b6debc72ef319fea14141e62f5db..7d097404a1daae8b842a6e7fbb5ccde42802e4ad 100644 (file)
@@ -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
index 53ab2a670752c14bbfaa703b72464db576ff164d..65aebd5763402cc8462655fd0d5fae6bfbe857cf 100644 (file)
@@ -1,4 +1,3 @@
-require 'tempfile'
 require 'time'
 require 'iconv'