diff --git a/klaus/tarutils.py b/klaus/tarutils.py index fcdf7f5f31cb24757410921f99c0cfe892159480..3eeb2d6afd1857fe6fb6b44c0f93f1e98b5606ea 100644 --- a/klaus/tarutils.py +++ b/klaus/tarutils.py @@ -39,7 +39,7 @@ class ListBytesIO(object): return b''.join(buf) -def tar_stream(repo, tree, mtime): +def tar_stream(repo, tree, mtime, format=''): """ Returns a generator that lazily assembles a .tar.gz archive, yielding it in pieces (bytestrings). To obtain the complete .tar.gz binary file, simply @@ -50,7 +50,7 @@ def tar_stream(repo, tree, mtime): time of all files in the resulting .tar.gz archive. """ buf = BytesIO() - with tarfile.open(None, "w", buf) as tar: + with tarfile.open(None, "w:%s" % format, buf) as tar: for entry_abspath, entry in walk_tree(repo, tree): blob = repo[entry.sha] data = ListBytesIO(blob.chunked) diff --git a/klaus/templates/tree.inc.html b/klaus/templates/tree.inc.html index 94481e2210becb155bcf27fc8bd45f2c7ca8dcf3..2a1b5d0e2ba01583f2310ca6160aa27110259f8f 100644 --- a/klaus/templates/tree.inc.html +++ b/klaus/templates/tree.inc.html @@ -1,6 +1,6 @@ <div class=tree> <h2>Tree @<a href="{{ url_for('commit', repo=repo.name, rev=rev) }}">{{ rev|shorten_sha1 }}</a> - <span>(<a href="{{ url_for('download', repo=repo.name, rev=rev) }}">Download tar</a>)</span> + <span>(<a href="{{ url_for('download', repo=repo.name, rev=rev) }}">Download .tar.gz</a>)</span> </h2> <ul> {% for _, name, fullpath in root_tree.dirs %} diff --git a/klaus/views.py b/klaus/views.py index 07c27fe5fdb40843e5985f2459c080a515f3d83b..dedbcff667224fb158776a3eefbc5d5ae7c92eae 100644 --- a/klaus/views.py +++ b/klaus/views.py @@ -235,10 +235,10 @@ class RawView(BlobViewMixin, BaseRepoView): class DownloadView(BaseRepoView): """ - Download a repo as a tar file + Download a repo as a tar.gz file """ def get_response(self): - tarname = "%s@%s.tar" % (self.context['repo'].name, self.context['rev']) + tarname = "%s@%s.tar.gz" % (self.context['repo'].name, self.context['rev']) headers = { 'Content-Disposition': "attachment; filename=%s" % tarname, 'Cache-Control': "no-store", # Disables browser caching @@ -247,11 +247,12 @@ class DownloadView(BaseRepoView): tar_stream = tarutils.tar_stream( self.context['repo'], self.context['blob_or_tree'], - self.context['commit'].commit_time + self.context['commit'].commit_time, + format="gz" ) return Response( tar_stream, - mimetype="application/tar", + mimetype="application/x-tgz", headers=headers )