diff options
-rw-r--r-- | doc/changelog.asciidoc | 3 | ||||
-rw-r--r-- | qutebrowser/utils/resources.py | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index b6385b015..e90c84a31 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -47,6 +47,9 @@ Fixed condition. - Worked around qutebrowser quitting when closing a KDE file dialog due to a Qt bug. +- Worked around a crash when trying to use qutebrowser after it's been + deleted/moved on disk (e.g. after a Python upgrade). It now shows an error + asking to run `:restart` instead. [[v3.1.1]] v3.1.1 (unreleased) diff --git a/qutebrowser/utils/resources.py b/qutebrowser/utils/resources.py index a40f9d2bd..a97a2e994 100644 --- a/qutebrowser/utils/resources.py +++ b/qutebrowser/utils/resources.py @@ -26,6 +26,7 @@ else: # pragma: no cover import qutebrowser _cache: Dict[str, str] = {} +_bin_cache: Dict[str, bytes] = {} _ResourceType = Union[Traversable, pathlib.Path] @@ -88,6 +89,10 @@ def preload() -> None: for name in _glob(resource_path, subdir, ext): _cache[name] = read_file(name) + for name in _glob(resource_path, 'img', '.png'): + # e.g. broken_qutebrowser_logo.png + _bin_cache[name] = read_file_binary(name) + def read_file(filename: str) -> str: """Get the contents of a file contained with qutebrowser. @@ -115,6 +120,9 @@ def read_file_binary(filename: str) -> bytes: Return: The file contents as a bytes object. """ + if filename in _bin_cache: + return _bin_cache[filename] + path = _path(filename) with _keyerror_workaround(): return path.read_bytes() |