userscripts: fix FIFO on Windows

The userscript FIFO on Windows suffered the same problem that open-editor
once did, because files on Windows can't be opened with write access by
two different processes. We kept the oshandle around and only closed it
when the process exited, which means that userscripts could not actually
write any commands to the FIFO.

This patch closes the file earlier, allowing the userscript to actually
write commands to it.

See also
https://lists.schokokeks.org/pipermail/qutebrowser/2016-September/000256.html
This commit is contained in:
Daniel Schadt 2016-09-06 18:03:53 +02:00
parent 7356e32b94
commit 1c76f121a2

View File

@ -280,14 +280,10 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
This also means the userscript *has* to use >> (append) rather than >
(overwrite) to write to the file!
Attributes:
_oshandle: The oshandle of the temp file.
"""
def __init__(self, win_id, parent=None):
super().__init__(win_id, parent)
self._oshandle = None
def _cleanup(self):
"""Clean up temporary files after the userscript finished."""
@ -301,12 +297,7 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
except OSError:
log.procs.exception("Failed to read command file!")
try:
os.close(self._oshandle)
except OSError:
log.procs.exception("Failed to close file handle!")
super()._cleanup()
self._oshandle = None
self.finished.emit()
@pyqtSlot()
@ -323,7 +314,9 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
self._kwargs = kwargs
try:
self._oshandle, self._filepath = tempfile.mkstemp(text=True)
handle = tempfile.NamedTemporaryFile(delete=False)
handle.close()
self._filepath = handle.name
except OSError as e:
message.error(self._win_id, "Error while creating tempfile: "
"{}".format(e))