Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Sascha Silbe <sascha-pgp@silbe.org>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] Catch errors while saving a message to disk for editing
Date: Sat,  2 Jul 2011 17:06:54 +0200	[thread overview]
Message-ID: <1309619214-2446-1-git-send-email-sascha-pgp@silbe.org> (raw)

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>
---
 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..256e314 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
+      write_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
+      write_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


             reply	other threads:[~2011-07-02 15:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-02 15:06 Sascha Silbe [this message]
2011-07-02 20:28 ` Alexander Shulgin
2011-07-02 21:54   ` Sascha Silbe
2011-07-02 21:56   ` [sup-devel] [PATCH v2] " Sascha Silbe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1309619214-2446-1-git-send-email-sascha-pgp@silbe.org \
    --to=sascha-pgp@silbe.org \
    --cc=sascha-ml-reply-to-2011-3@silbe.org \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox