From 06b07617552b09b641f8483b67279f88b6a0bbe7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 27 May 2014 07:43:07 +0200 Subject: [PATCH] Always clean up editor tempfiles, even on exit != 0 --- qutebrowser/utils/editor.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/qutebrowser/utils/editor.py b/qutebrowser/utils/editor.py index 6c627619e..4efa3f2a0 100644 --- a/qutebrowser/utils/editor.py +++ b/qutebrowser/utils/editor.py @@ -61,18 +61,21 @@ class ExternalEditor(QObject): editing_finished: If process exited normally. """ logger.debug("Editor closed") - if exitcode != 0: - message.error("Editor did quit abnormally (status {})!".format( - exitcode)) - return if exitstatus != QProcess.NormalExit: - # No error here, since we already handle this in on_editor_error + # No error/cleanup here, since we already handle this in + # on_proc_error return - with open(self.filename, 'r') as f: - text = ''.join(f.readlines()) - logger.debug("Read back: {}".format(text)) - self._cleanup() - self.editing_finished.emit(text) + try: + if exitcode != 0: + message.error("Editor did quit abnormally (status {})!".format( + exitcode)) + return + with open(self.filename, 'r') as f: + text = ''.join(f.readlines()) + logger.debug("Read back: {}".format(text)) + self.editing_finished.emit(text) + finally: + self._cleanup() def on_proc_error(self, error): """Display an error message and clean up when editor crashed."""