From 5a5fac63742874bef2ccd38abdaade530014a262 Mon Sep 17 00:00:00 2001 From: Peter Selten Date: Tue, 13 Aug 2019 23:57:53 +0200 Subject: [PATCH] Add file extensions when downloading from data libraries. Both in the compressed and uncompressed datasets. --- lib/galaxy/webapps/galaxy/api/library_datasets.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/webapps/galaxy/api/library_datasets.py b/lib/galaxy/webapps/galaxy/api/library_datasets.py index 7812afb538d..e16bf43f9d5 100644 --- a/lib/galaxy/webapps/galaxy/api/library_datasets.py +++ b/lib/galaxy/webapps/galaxy/api/library_datasets.py @@ -623,6 +623,9 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin, Libra zpath = os.path.split(path)[-1] # comes as base_name/fname outfname, zpathext = os.path.splitext(zpath) + if zpathext == '': + path = '.'.join([path, ldda.extension]) # Add extension if we don't have one + if is_composite: # need to add all the components from the extra_files_path to the zip if zpathext == '': @@ -647,6 +650,8 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin, Libra efp, fname = os.path.split(fpath) if fname > '': fname = fname.translate(trantab) + if zpathext == '': + fname = '.'.join([fname, ldda.extension]) # Add extension if we don't have one try: if format == 'zip': archive.add(fpath, fname) @@ -702,7 +707,11 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin, Libra fStat = os.stat(dataset.file_name) trans.response.set_content_type(ldda.get_mime()) trans.response.headers['Content-Length'] = int(fStat.st_size) - fname = ldda.name + zname, zext = os.path.splitext(ldda.name) + if zext == '': + fname = '.'.join([ldda.name, ldda.extension]) + else: + fname = ldda.name fname = ''.join(c in util.FILENAME_VALID_CHARS and c or '_' for c in fname)[0:150] trans.response.headers["Content-Disposition"] = 'attachment; filename="%s"' % fname try: