Skip to content

Commit

Permalink
Merge pull request #214 from jelmer/archive-subdir
Browse files Browse the repository at this point in the history
Put files in a tarball in a subdirectory.
  • Loading branch information
jonashaag authored Jun 19, 2018
2 parents 05014e0 + 5116934 commit 57c4b8b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions klaus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 57c4b8b

Please sign in to comment.