[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-devel] [PATCH v2] Catch errors while saving a message to disk for editing



Running out of disk space in /tmp caused sup to crash with the following
exception:

--- Errno::ENOSPC from thread: main
No space left on device - /tmp/sascha_silbe/sup.reply-mode20110702-31427-rtg4kl-0
/usr/lib/ruby/1.8/tempfile.rb:97:in `close'
/usr/lib/ruby/1.8/tempfile.rb:97:in `_close'
/usr/lib/ruby/1.8/tempfile.rb:112:in `close'
./lib/sup/modes/edit-message-mode.rb:180:in `edit_message'
./lib/sup/mode.rb:59:in `send'
./lib/sup/mode.rb:59:in `handle_input'
./lib/sup/buffer.rb:278:in `handle_input'
bin/sup:271

Signed-off-by: Sascha Silbe <sascha-pgp@silbe.org>
---
 v1->v2: fix typo (save_message_to_file vs. write_message_to_file)

 lib/sup/modes/edit-message-mode.rb |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index 5ed7833..4387f7b 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -172,12 +172,21 @@ def edit_to; edit_field "To" end
   def edit_cc; edit_field "Cc" end
   def edit_subject; edit_field "Subject" end

-  def edit_message
-    @file = Tempfile.new "sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}"
+  def save_message_to_file
+    @file = Tempfile.new ["sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}", ".eml"]
     @file.puts format_headers(@header - NON_EDITABLE_HEADERS).first
     @file.puts
     @file.puts @body.join("\n")
     @file.close
+  end
+
+  def edit_message
+    begin
+      save_message_to_file
+    rescue SystemCallError => e
+      BufferManager.flash "Can't save message to file: #{e.message}"
+      return
+    end

     editor = $config[:editor] || ENV['EDITOR'] || "/usr/bin/vi"

@@ -197,11 +206,12 @@ def edit_message
   end

   def edit_message_async
-    @file = Tempfile.new ["sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}", ".eml"]
-    @file.puts format_headers(@header - NON_EDITABLE_HEADERS).first
-    @file.puts
-    @file.puts @body.join("\n")
-    @file.close
+    begin
+      save_message_to_file
+    rescue SystemCallError => e
+      BufferManager.flash "Can't save message to file: #{e.message}"
+      return
+    end

     @mtime = File.mtime @file.path

--
1.7.4.1

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel