From 5116934c27c8400541c3ca009be5f3e6f112c217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sun, 17 Jun 2018 17:04:12 +0100 Subject: [PATCH] Put files in a tarball in a subdirectory. Fixes #204 --- klaus/views.py | 8 +++++--- setup.py | 2 +- tests/test_views.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/klaus/views.py b/klaus/views.py index bcf7e9bc..83e6e5fc 100644 --- a/klaus/views.py +++ b/klaus/views.py @@ -434,8 +434,9 @@ def get_response(self): class DownloadView(BaseRepoView): """Download a repo as a tar.gz file.""" def get_response(self): - tarname = "%s@%s.tar.gz" % (self.context['repo'].name, - sanitize_branch_name(self.context['rev'])) + basename = "%s@%s" % (self.context['repo'].name, + sanitize_branch_name(self.context['rev'])) + tarname = basename + ".tar.gz" headers = { 'Content-Disposition': "attachment; filename=%s" % tarname, 'Cache-Control': "no-store", # Disables browser caching @@ -445,7 +446,8 @@ def get_response(self): self.context['repo'], self.context['blob_or_tree'], self.context['commit'].commit_time, - format="gz" + format="gz", + prefix=encode_for_git(basename), ) return Response( tar_stream, diff --git a/setup.py b/setup.py index 426e351e..423992e6 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ def install_data_files_hack(): install_data_files_hack() -requires = ['six', 'flask', 'pygments', 'dulwich>=0.13.0', 'httpauth', 'humanize'] +requires = ['six', 'flask', 'pygments', 'dulwich>=0.19.3', 'httpauth', 'humanize'] setup( name='klaus', diff --git a/tests/test_views.py b/tests/test_views.py index 87e95806..107f1896 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -11,7 +11,7 @@ def test_download(): response_body = BytesIO(response.raw.read()) tarball = tarfile.TarFile.gzopen("test.tar.gz", fileobj=response_body) with contextlib.closing(tarball): - assert tarball.extractfile('test.c').read() == b'int a;\n' + assert tarball.extractfile('test_repo@master/test.c').read() == b'int a;\n' def test_no_newline_at_end_of_file():