Commits

Marcin Kuzminski committed bb0309b

fixed tests, and archival method

  • Participants
  • Parent commits 8caaa99

Comments (0)

Files changed (3)

rhodecode/controllers/files.py

         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)
                 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')

rhodecode/lib/vcs/backends/hg/changeset.py

         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:

rhodecode/tests/functional/test_files.py

         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))
 
              [('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):