From e15223211cf0f689f89139d27ccd18d648c8ad62 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 26 Jun 2023 13:27:24 +0200 Subject: Fix :print --pdf with subdirectories Fixes #5160 --- doc/changelog.asciidoc | 2 ++ qutebrowser/components/misccommands.py | 8 ++++++-- tests/end2end/features/misc.feature | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 551ba6a6a..5f2e945e6 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -170,6 +170,8 @@ Fixed - Crash when using QtWebKit with PAC and the file has an invalid encoding. - Crash with the "tiramisu" notification server. - Crash when the "herbe" notification presenter doesn't start correctly. +- Crash when using `:print --pdf` with a directory where its parent directory + did not exist. [[v2.5.4]] v2.5.4 (2023-03-13) diff --git a/qutebrowser/components/misccommands.py b/qutebrowser/components/misccommands.py index 0b3a918d1..5bbf93e6a 100644 --- a/qutebrowser/components/misccommands.py +++ b/qutebrowser/components/misccommands.py @@ -96,8 +96,12 @@ def _print_pdf(tab: apitypes.Tab, filename: str) -> None: tab.printing.check_pdf_support() filename = os.path.expanduser(filename) directory = os.path.dirname(filename) - if directory and not os.path.exists(directory): - os.mkdir(directory) + + try: + os.makedirs(directory, exist_ok=True) + except OSError as e: + raise cmdutils.CommandError(e) + tab.printing.to_pdf(filename) _LOGGER.debug("Print to file: {}".format(filename)) diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 480ce7339..b9cc2a513 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -313,6 +313,12 @@ Feature: Various utility commands. And I wait for "Print to file: *" in the log or skip the test Then the PDF hello.pdf should exist in the tmpdir + Scenario: print --pdf with subdirectory + When I open data/hello.txt + And I run :print --pdf (tmpdir)/subdir/subdir2/hello.pdf + And I wait for "Print to file: *" in the log or skip the test + Then no crash should happen + ## https://github.com/qutebrowser/qutebrowser/issues/504 Scenario: Focusing download widget via Tab -- cgit v1.2.3-54-g00ecf