Mercurial > kallithea
changeset 2267:b872bc10f4ec beta
cleanup code of get archive for repositories
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 15 May 2012 19:29:02 +0200 |
parents | 64ef1b886336 |
children | f1467dfcf093 |
files | rhodecode/controllers/files.py rhodecode/lib/vcs/backends/hg/changeset.py |
diffstat | 2 files changed, 10 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/controllers/files.py Mon May 14 22:25:49 2012 +0200 +++ b/rhodecode/controllers/files.py Tue May 15 19:29:02 2012 +0200 @@ -26,6 +26,7 @@ import os import logging import traceback +import tempfile from pylons import request, response, tmpl_context as c, url from pylons.i18n.translation import _ @@ -359,25 +360,22 @@ except (ImproperArchiveTypeError, KeyError): return _('Unknown archive type') + archive = tempfile.NamedTemporaryFile(mode='w+r+b') + cs.fill_archive(stream=archive, kind=fileformat, subrepos=subrepos) + response.content_type = content_type response.content_disposition = 'attachment; filename=%s-%s%s' \ - % (repo_name, revision, ext) - - import tempfile - archive = tempfile.mkstemp()[1] - t = open(archive, 'wb') - cs.fill_archive(stream=t, kind=fileformat, subrepos=subrepos) + % (repo_name, revision[:12], ext) + response.content_length = str(os.path.getsize(archive.name)) - def get_chunked_archive(archive): - stream = open(archive, 'rb') + def get_chunked_archive(tmpfile): while True: - data = stream.read(4096) + data = tmpfile.read(16 * 1024) if not data: - os.remove(archive) + tmpfile.close() break yield data - - return get_chunked_archive(archive) + return get_chunked_archive(tmpfile=archive) @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
--- a/rhodecode/lib/vcs/backends/hg/changeset.py Mon May 14 22:25:49 2012 +0200 +++ b/rhodecode/lib/vcs/backends/hg/changeset.py Tue May 15 19:29:02 2012 +0200 @@ -263,8 +263,6 @@ archival.archive(self.repository._repo, stream, self.raw_id, kind, prefix=prefix, subrepos=subrepos) - #stream.close() - if stream.closed and hasattr(stream, 'name'): stream = open(stream.name, 'rb') elif hasattr(stream, 'mode') and 'r' not in stream.mode: