summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-06-26 13:27:24 +0200
committerFlorian Bruhin <me@the-compiler.org>2023-06-26 13:50:19 +0200
commite15223211cf0f689f89139d27ccd18d648c8ad62 (patch)
treea4a4dd6145d5a38b0b1087e05e0b8668567fac2d
parentf1d4f248b3520515605ac18e3b39e0f2860bf5d9 (diff)
downloadqutebrowser-e15223211cf0f689f89139d27ccd18d648c8ad62.tar.gz
qutebrowser-e15223211cf0f689f89139d27ccd18d648c8ad62.zip
Fix :print --pdf with subdirectories
Fixes #5160
-rw-r--r--doc/changelog.asciidoc2
-rw-r--r--qutebrowser/components/misccommands.py8
-rw-r--r--tests/end2end/features/misc.feature6
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