# HG changeset patch # User Marcin Kuzminski # Date 2012-05-16 01:20:52 # Node ID bb0309b4e1ee7081270b9fcec90b37a22046594a # Parent 8caaa9955f5e60701e5acba8a806582c6b16524c fixed tests, and archival method diff --git a/rhodecode/controllers/files.py b/rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py +++ b/rhodecode/controllers/files.py @@ -360,9 +360,9 @@ class FilesController(BaseRepoController except (ImproperArchiveTypeError, KeyError): return _('Unknown archive type') - archive = tempfile.NamedTemporaryFile(mode='w+r+b') + archive = tempfile.NamedTemporaryFile(mode='w+r+b', delete=False) cs.fill_archive(stream=archive, kind=fileformat, subrepos=subrepos) - + archive.close() response.content_type = content_type response.content_disposition = 'attachment; filename=%s-%s%s' \ % (repo_name, revision[:12], ext) @@ -373,9 +373,10 @@ class FilesController(BaseRepoController data = tmpfile.read(16 * 1024) if not data: tmpfile.close() + os.unlink(tmpfile.name) break yield data - return get_chunked_archive(tmpfile=archive) + return get_chunked_archive(tmpfile=open(archive.name,'rb')) @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin') diff --git a/rhodecode/lib/vcs/backends/hg/changeset.py b/rhodecode/lib/vcs/backends/hg/changeset.py --- a/rhodecode/lib/vcs/backends/hg/changeset.py +++ b/rhodecode/lib/vcs/backends/hg/changeset.py @@ -260,9 +260,11 @@ class MercurialChangeset(BaseChangeset): elif prefix.strip() == '': raise VCSError("Prefix cannot be empty") + print stream.closed archival.archive(self.repository._repo, stream, self.raw_id, kind, prefix=prefix, subrepos=subrepos) - + print stream.closed + if stream.closed and hasattr(stream, 'name'): stream = open(stream.name, 'rb') elif hasattr(stream, 'mode') and 'r' not in stream.mode: diff --git a/rhodecode/tests/functional/test_files.py b/rhodecode/tests/functional/test_files.py --- a/rhodecode/tests/functional/test_files.py +++ b/rhodecode/tests/functional/test_files.py @@ -190,10 +190,11 @@ class TestFilesController(TestController self.log_user() for arch_ext, info in ARCHIVE_SPECS.items(): + short = '27cd5cce30c9%s' % arch_ext fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext - filename = '%s-%s' % (HG_REPO, fname) - - response = self.app.get(url(controller='files', action='archivefile', + filename = '%s-%s' % (HG_REPO, short) + response = self.app.get(url(controller='files', + action='archivefile', repo_name=HG_REPO, fname=fname)) @@ -202,7 +203,8 @@ class TestFilesController(TestController [('Pragma', 'no-cache'), ('Cache-Control', 'no-cache'), ('Content-Type', '%s; charset=utf-8' % info[0]), - ('Content-Disposition', 'attachment; filename=%s' % filename),] + ('Content-Disposition', 'attachment; filename=%s' % filename), + ] ) def test_archival_wrong_ext(self):