##// END OF EJS Templates
fixes issue #455 Creating an archive generates an exception on Windows...
marcink -
r2318:058e2743 beta
parent child Browse files
Show More
@@ -361,26 +361,26 b' class FilesController(BaseRepoController'
361 361 except (ImproperArchiveTypeError, KeyError):
362 362 return _('Unknown archive type')
363 363
364 fd, _archive_name = tempfile.mkstemp(suffix='rcarchive')
365 with open(_archive_name, 'wb') as f:
366 cs.fill_archive(stream=f, kind=fileformat, subrepos=subrepos)
367
368 content_disposition = 'attachment; filename=%s-%s%s' \
369 % (repo_name, revision[:12], ext)
370 content_length = os.path.getsize(_archive_name)
364 fd, archive = tempfile.mkstemp()
365 t = open(archive, 'wb')
366 cs.fill_archive(stream=t, kind=fileformat, subrepos=subrepos)
367 t.close()
371 368
372 headers = [('Content-Disposition', str(content_disposition)),
373 ('Content-Type', str(content_type)),
374 ('Content-Length', str(content_length))]
369 def get_chunked_archive(archive):
370 stream = open(archive, 'rb')
371 while True:
372 data = stream.read(16 * 1024)
373 if not data:
374 stream.close()
375 os.close(fd)
376 os.remove(archive)
377 break
378 yield data
375 379
376 class _DestroyingFileWrapper(_FileIter):
377 def close(self):
378 self.file.close
379 os.remove(self.file.name)
380
381 request.environ['wsgi.file_wrapper'] = _DestroyingFileWrapper
382 fapp = FileApp(_archive_name, headers=headers)
383 return fapp(request.environ, self.start_response)
380 response.content_disposition = str('attachment; filename=%s-%s%s' \
381 % (repo_name, revision[:12], ext))
382 response.content_type = str(content_type)
383 return get_chunked_archive(archive)
384 384
385 385 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
386 386 'repository.admin')
@@ -200,9 +200,10 b' class TestFilesController(TestController'
200 200
201 201 self.assertEqual(response.status, '200 OK')
202 202 heads = [
203 ('Content-Type', 'text/html; charset=utf-8'),
204 ('Content-Length', '0'), ('Pragma', 'no-cache'),
205 ('Cache-Control', 'no-cache')
203 ('Pragma', 'no-cache'),
204 ('Cache-Control', 'no-cache'),
205 ('Content-Disposition', 'attachment; filename=%s' % filename),
206 ('Content-Type', '%s; charset=utf-8' % info[0]),
206 207 ]
207 208 self.assertEqual(response.response._headers.items(), heads)
208 209
@@ -212,7 +213,8 b' class TestFilesController(TestController'
212 213 for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
213 214 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
214 215
215 response = self.app.get(url(controller='files', action='archivefile',
216 response = self.app.get(url(controller='files',
217 action='archivefile',
216 218 repo_name=HG_REPO,
217 219 fname=fname))
218 220 response.mustcontain('Unknown archive type')
@@ -220,10 +222,11 b' class TestFilesController(TestController'
220 222 def test_archival_wrong_revision(self):
221 223 self.log_user()
222 224
223 for rev in ['00x000000', 'tar', 'wrong', '@##$@$424213232', '232dffcd']:
225 for rev in ['00x000000', 'tar', 'wrong', '@##$@$42413232', '232dffcd']:
224 226 fname = '%s.zip' % rev
225 227
226 response = self.app.get(url(controller='files', action='archivefile',
228 response = self.app.get(url(controller='files',
229 action='archivefile',
227 230 repo_name=HG_REPO,
228 231 fname=fname))
229 232 response.mustcontain('Unknown revision')
General Comments 0
You need to be logged in to leave comments. Login now