diff --git a/qutebrowser/browser/qtnetworkdownloads.py b/qutebrowser/browser/qtnetworkdownloads.py index c9d6d7024..09da5fea2 100644 --- a/qutebrowser/browser/qtnetworkdownloads.py +++ b/qutebrowser/browser/qtnetworkdownloads.py @@ -131,11 +131,22 @@ class DownloadItem(downloads.AbstractDownloadItem): self._reply.deleteLater() self._reply = None if self.fileobj is not None: + pos = self.fileobj.tell() + log.downloads.debug(f"File position at error: {pos}") try: self.fileobj.close() except OSError: log.downloads.exception("Error while closing file object") + if pos == 0: + # Emtpy remaining file + filename = self._get_open_filename() + log.downloads.debug(f"Removing empty file at {filename}") + try: + os.remove(filename) + except OSError: + log.downloads.exception("Error while removing empty file") + def _init_reply(self, reply): """Set a new reply and connect its signals. diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 7d013c367..d0646efb8 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -578,11 +578,13 @@ Feature: Downloading things from a website. When I set downloads.location.prompt to false And I run :download http://localhost:(port)/redirect/12 --dest redirection Then the error "Download error: Too many redirects" should be shown + And the downloaded file redirection should not exist Scenario: Downloading with redirect to itself When I set downloads.location.prompt to false And I run :download http://localhost:(port)/redirect-self Then the error "Download error: Too many redirects" should be shown + And the downloaded file redirect-self should not exist Scenario: Downloading with absolute redirect When I set downloads.location.prompt to false @@ -603,6 +605,7 @@ Feature: Downloading things from a website. # First error is due to the load-insecurely value above Then the error "Certificate error: The certificate is self-signed, and untrusted" should be shown And the error "Download error: Insecure redirect" should be shown + And the downloaded file download.bin should not exist ## Other