Show More
@@ -65,6 +65,8 b' static_files = true' | |||||
65 | lang = en |
|
65 | lang = en | |
66 | cache_dir = %(here)s/data |
|
66 | cache_dir = %(here)s/data | |
67 | index_dir = %(here)s/data/index |
|
67 | index_dir = %(here)s/data/index | |
|
68 | # set this path to use archive download cache | |||
|
69 | #archive_cache_dir = /tmp/rhodecode_tarballcache | |||
68 | app_instance_uuid = rc-develop |
|
70 | app_instance_uuid = rc-develop | |
69 | cut_off_limit = 256000 |
|
71 | cut_off_limit = 256000 | |
70 | vcs_full_cache = True |
|
72 | vcs_full_cache = True |
@@ -65,6 +65,8 b' static_files = true' | |||||
65 | lang = en |
|
65 | lang = en | |
66 | cache_dir = %(here)s/data |
|
66 | cache_dir = %(here)s/data | |
67 | index_dir = %(here)s/data/index |
|
67 | index_dir = %(here)s/data/index | |
|
68 | # set this path to use archive download cache | |||
|
69 | #archive_cache_dir = /tmp/rhodecode_tarballcache | |||
68 | app_instance_uuid = rc-production |
|
70 | app_instance_uuid = rc-production | |
69 | cut_off_limit = 256000 |
|
71 | cut_off_limit = 256000 | |
70 | vcs_full_cache = True |
|
72 | vcs_full_cache = True |
@@ -65,6 +65,8 b' static_files = true' | |||||
65 | lang = en |
|
65 | lang = en | |
66 | cache_dir = %(here)s/data |
|
66 | cache_dir = %(here)s/data | |
67 | index_dir = %(here)s/data/index |
|
67 | index_dir = %(here)s/data/index | |
|
68 | # set this path to use archive download cache | |||
|
69 | #archive_cache_dir = /tmp/rhodecode_tarballcache | |||
68 | app_instance_uuid = ${app_instance_uuid} |
|
70 | app_instance_uuid = ${app_instance_uuid} | |
69 | cut_off_limit = 256000 |
|
71 | cut_off_limit = 256000 | |
70 | vcs_full_cache = True |
|
72 | vcs_full_cache = True |
@@ -27,6 +27,7 b' import os' | |||||
27 | import logging |
|
27 | import logging | |
28 | import traceback |
|
28 | import traceback | |
29 | import tempfile |
|
29 | import tempfile | |
|
30 | import shutil | |||
30 |
|
31 | |||
31 | from pylons import request, response, tmpl_context as c, url |
|
32 | from pylons import request, response, tmpl_context as c, url | |
32 | from pylons.i18n.translation import _ |
|
33 | from pylons.i18n.translation import _ | |
@@ -429,11 +430,40 b' class FilesController(BaseRepoController' | |||||
429 | return _('Empty repository') |
|
430 | return _('Empty repository') | |
430 | except (ImproperArchiveTypeError, KeyError): |
|
431 | except (ImproperArchiveTypeError, KeyError): | |
431 | return _('Unknown archive type') |
|
432 | return _('Unknown archive type') | |
|
433 | # archive cache | |||
|
434 | from rhodecode import CONFIG | |||
|
435 | rev_name = cs.raw_id[:12] | |||
|
436 | archive_name = '%s-%s%s' % (safe_str(repo_name.replace('/', '_')), | |||
|
437 | safe_str(rev_name), ext) | |||
432 |
|
438 | |||
433 | fd, archive = tempfile.mkstemp() |
|
439 | use_cached_archive = False # defines if we use cached version of archive | |
434 | t = open(archive, 'wb') |
|
440 | archive_cache_enabled = CONFIG.get('archive_cache_dir') | |
435 | cs.fill_archive(stream=t, kind=fileformat, subrepos=subrepos) |
|
441 | if not subrepos and archive_cache_enabled: | |
436 | t.close() |
|
442 | #check if we it's ok to write | |
|
443 | if not os.path.isdir(CONFIG['archive_cache_dir']): | |||
|
444 | os.makedirs(CONFIG['archive_cache_dir']) | |||
|
445 | cached_archive_path = os.path.join(CONFIG['archive_cache_dir'], archive_name) | |||
|
446 | if os.path.isfile(cached_archive_path): | |||
|
447 | log.debug('Found cached archive in %s' % cached_archive_path) | |||
|
448 | fd, archive = None, cached_archive_path | |||
|
449 | use_cached_archive = True | |||
|
450 | else: | |||
|
451 | log.debug('Archive %s is not yet cached' % (archive_name)) | |||
|
452 | ||||
|
453 | if not use_cached_archive: | |||
|
454 | #generate new archive | |||
|
455 | try: | |||
|
456 | fd, archive = tempfile.mkstemp() | |||
|
457 | t = open(archive, 'wb') | |||
|
458 | log.debug('Creating new temp archive in %s' % archive) | |||
|
459 | cs.fill_archive(stream=t, kind=fileformat, subrepos=subrepos) | |||
|
460 | if archive_cache_enabled: | |||
|
461 | #if we generated the archive and use cache rename that | |||
|
462 | log.debug('Storing new archive in %s' % cached_archive_path) | |||
|
463 | shutil.move(archive, cached_archive_path) | |||
|
464 | archive = cached_archive_path | |||
|
465 | finally: | |||
|
466 | t.close() | |||
437 |
|
467 | |||
438 | def get_chunked_archive(archive): |
|
468 | def get_chunked_archive(archive): | |
439 | stream = open(archive, 'rb') |
|
469 | stream = open(archive, 'rb') | |
@@ -441,14 +471,15 b' class FilesController(BaseRepoController' | |||||
441 | data = stream.read(16 * 1024) |
|
471 | data = stream.read(16 * 1024) | |
442 | if not data: |
|
472 | if not data: | |
443 | stream.close() |
|
473 | stream.close() | |
444 | os.close(fd) |
|
474 | if fd: # fd means we used temporary file | |
445 |
os. |
|
475 | os.close(fd) | |
|
476 | if not archive_cache_enabled: | |||
|
477 | log.debug('Destroing temp archive %s' % archive) | |||
|
478 | os.remove(archive) | |||
446 | break |
|
479 | break | |
447 | yield data |
|
480 | yield data | |
448 |
|
481 | |||
449 |
response.content_disposition = str('attachment; filename=%s |
|
482 | response.content_disposition = str('attachment; filename=%s' % (archive_name)) | |
450 | % (safe_str(repo_name), |
|
|||
451 | safe_str(revision), ext)) |
|
|||
452 | response.content_type = str(content_type) |
|
483 | response.content_type = str(content_type) | |
453 | return get_chunked_archive(archive) |
|
484 | return get_chunked_archive(archive) | |
454 |
|
485 |
@@ -65,6 +65,8 b' static_files = true' | |||||
65 | lang = en |
|
65 | lang = en | |
66 | cache_dir = /tmp/rc/data |
|
66 | cache_dir = /tmp/rc/data | |
67 | index_dir = /tmp/rc/index |
|
67 | index_dir = /tmp/rc/index | |
|
68 | # set this path to use archive download cache | |||
|
69 | #archive_cache_dir = /tmp/rhodecode_tarballcache | |||
68 | app_instance_uuid = develop-test |
|
70 | app_instance_uuid = develop-test | |
69 | cut_off_limit = 256000 |
|
71 | cut_off_limit = 256000 | |
70 | vcs_full_cache = False |
|
72 | vcs_full_cache = False |
General Comments 0
You need to be logged in to leave comments.
Login now