##// 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 except (ImproperArchiveTypeError, KeyError):
361 except (ImproperArchiveTypeError, KeyError):
362 return _('Unknown archive type')
362 return _('Unknown archive type')
363
363
364 fd, _archive_name = tempfile.mkstemp(suffix='rcarchive')
364 fd, archive = tempfile.mkstemp()
365 with open(_archive_name, 'wb') as f:
365 t = open(archive, 'wb')
366 cs.fill_archive(stream=f, kind=fileformat, subrepos=subrepos)
366 cs.fill_archive(stream=t, kind=fileformat, subrepos=subrepos)
367
367 t.close()
368 content_disposition = 'attachment; filename=%s-%s%s' \
369 % (repo_name, revision[:12], ext)
370 content_length = os.path.getsize(_archive_name)
371
368
372 headers = [('Content-Disposition', str(content_disposition)),
369 def get_chunked_archive(archive):
373 ('Content-Type', str(content_type)),
370 stream = open(archive, 'rb')
374 ('Content-Length', str(content_length))]
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):
380 response.content_disposition = str('attachment; filename=%s-%s%s' \
377 def close(self):
381 % (repo_name, revision[:12], ext))
378 self.file.close
382 response.content_type = str(content_type)
379 os.remove(self.file.name)
383 return get_chunked_archive(archive)
380
381 request.environ['wsgi.file_wrapper'] = _DestroyingFileWrapper
382 fapp = FileApp(_archive_name, headers=headers)
383 return fapp(request.environ, self.start_response)
384
384
385 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
385 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
386 'repository.admin')
386 'repository.admin')
@@ -200,9 +200,10 b' class TestFilesController(TestController'
200
200
201 self.assertEqual(response.status, '200 OK')
201 self.assertEqual(response.status, '200 OK')
202 heads = [
202 heads = [
203 ('Content-Type', 'text/html; charset=utf-8'),
203 ('Pragma', 'no-cache'),
204 ('Content-Length', '0'), ('Pragma', 'no-cache'),
204 ('Cache-Control', 'no-cache'),
205 ('Cache-Control', 'no-cache')
205 ('Content-Disposition', 'attachment; filename=%s' % filename),
206 ('Content-Type', '%s; charset=utf-8' % info[0]),
206 ]
207 ]
207 self.assertEqual(response.response._headers.items(), heads)
208 self.assertEqual(response.response._headers.items(), heads)
208
209
@@ -212,7 +213,8 b' class TestFilesController(TestController'
212 for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
213 for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
213 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
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 repo_name=HG_REPO,
218 repo_name=HG_REPO,
217 fname=fname))
219 fname=fname))
218 response.mustcontain('Unknown archive type')
220 response.mustcontain('Unknown archive type')
@@ -220,10 +222,11 b' class TestFilesController(TestController'
220 def test_archival_wrong_revision(self):
222 def test_archival_wrong_revision(self):
221 self.log_user()
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 fname = '%s.zip' % rev
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 repo_name=HG_REPO,
230 repo_name=HG_REPO,
228 fname=fname))
231 fname=fname))
229 response.mustcontain('Unknown revision')
232 response.mustcontain('Unknown revision')
General Comments 0
You need to be logged in to leave comments. Login now