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.
This commit is contained in:
Florian Bruhin 2016-05-01 22:47:03 +02:00
parent 43908dba20
commit 3eeacd7e09

View File

@ -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):