From 3eeacd7e093472a1c8fd58ff75b4aec8567457f5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 1 May 2016 22:47:03 +0200 Subject: [PATCH] Fix userscripts on Windows If the process emitted error() and then finished(), we already set self._filepath to None and did other cleanup. Instead we do the file reading inside _cleanup and call that from on_process_error and on_process_finished. --- qutebrowser/commands/userscripts.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index b688297eb..270c2e2a8 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -251,6 +251,14 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner): """Clean up temporary files after the userscript finished.""" if self._cleaned_up: return + + try: + with open(self._filepath, 'r', encoding='utf-8') as f: + for line in f: + self.got_cmd.emit(line.rstrip()) + except OSError: + log.procs.exception("Failed to read command file!") + try: os.close(self._oshandle) except OSError: @@ -266,12 +274,6 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner): @pyqtSlot() def on_proc_finished(self): """Read back the commands when the process finished.""" - try: - with open(self._filepath, 'r', encoding='utf-8') as f: - for line in f: - self.got_cmd.emit(line.rstrip()) - except OSError: - log.procs.exception("Failed to read command file!") self._cleanup() def run(self, cmd, *args, env=None, verbose=False):