Preserve filename in temporary downloads
When downloading a file into a temporary location for external open or pdfjs, it used to prepend a random string to the filename. This means that downloading a file opened with pdfjs would have an unwanted mangled filename. Instead of adding a prefix to the filename, this puts the file with its filename intact in a unique temporary directory.
This commit is contained in:
parent
eb06ac3f8b
commit
2274dd2d39
|
|
@ -7,6 +7,7 @@
|
|||
import re
|
||||
import sys
|
||||
import html
|
||||
import io as _io
|
||||
import os.path
|
||||
import collections
|
||||
import functools
|
||||
|
|
@ -813,7 +814,8 @@ class AbstractDownloadItem(QObject):
|
|||
if filename is None: # pragma: no cover
|
||||
log.downloads.error("No filename to open the download!")
|
||||
return
|
||||
self.pdfjs_requested.emit(os.path.basename(filename),
|
||||
dirname = os.path.basename(os.path.dirname(filename))
|
||||
self.pdfjs_requested.emit(os.path.join(dirname, os.path.basename(filename)),
|
||||
self.url())
|
||||
|
||||
def cancel_for_origin(self) -> bool:
|
||||
|
|
@ -1373,8 +1375,8 @@ class TempDownloadManager:
|
|||
# Make sure that the filename is not too long
|
||||
suggested_name = utils.elide_filename(suggested_name, 50)
|
||||
# pylint: disable=consider-using-with
|
||||
fobj = tempfile.NamedTemporaryFile(dir=tmpdir.name, delete=False,
|
||||
suffix='_' + suggested_name)
|
||||
tmpfiledir = tempfile.mkdtemp(dir=tmpdir.name)
|
||||
fobj = _io.open(os.path.join(tmpfiledir, suggested_name), 'w+b')
|
||||
self.files.append(fobj)
|
||||
return fobj
|
||||
|
||||
|
|
|
|||
|
|
@ -518,8 +518,6 @@ def qute_pdfjs(url: QUrl) -> _HandlerRet:
|
|||
filename = QUrlQuery(url).queryItemValue('filename')
|
||||
if not filename:
|
||||
raise UrlInvalidError("Missing filename")
|
||||
if '/' in filename or os.sep in filename:
|
||||
raise RequestDeniedError("Path separator in filename.")
|
||||
|
||||
path = _pdf_path(filename)
|
||||
with open(path, 'rb') as f:
|
||||
|
|
|
|||
Loading…
Reference in New Issue