From 1c76f121a2698deb0b7ff9f37940cc7b9f0a10f8 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 6 Sep 2016 18:03:53 +0200 Subject: [PATCH] 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 --- qutebrowser/commands/userscripts.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 0a8b19524..65af02609 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -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))