From 30534413beed83bf7f1d5cdadd9198fc71ac6426 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Thu, 6 Jun 2019 21:05:45 +0200 Subject: [PATCH] archival: allowed using .tbz2 and .tgz extensions. --- .../apps/repository/tests/test_repo_files.py | 10 +++++----- rhodecode/apps/repository/views/repo_files.py | 3 +-- rhodecode/lib/vcs/backends/base.py | 2 +- rhodecode/lib/vcs/conf/settings.py | 16 ++++++++++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/rhodecode/apps/repository/tests/test_repo_files.py b/rhodecode/apps/repository/tests/test_repo_files.py index 544334c7..8c92abed 100644 --- a/rhodecode/apps/repository/tests/test_repo_files.py +++ b/rhodecode/apps/repository/tests/test_repo_files.py @@ -521,10 +521,10 @@ class TestRepositoryArchival(object): def test_archival(self, backend): backend.enable_downloads() commit = backend.repo.get_commit(commit_idx=173) - for archive, info in settings.ARCHIVE_SPECS.items(): - mime_type, arch_ext = info - short = commit.short_id + arch_ext - fname = commit.raw_id + arch_ext + for a_type, content_type, extension in settings.ARCHIVE_SPECS: + + short = commit.short_id + extension + fname = commit.raw_id + extension filename = '%s-%s' % (backend.repo_name, short) response = self.app.get( route_path('repo_archivefile', @@ -534,7 +534,7 @@ class TestRepositoryArchival(object): assert response.status == '200 OK' headers = [ ('Content-Disposition', 'attachment; filename=%s' % filename), - ('Content-Type', '%s' % mime_type), + ('Content-Type', '%s' % content_type), ] for header in headers: diff --git a/rhodecode/apps/repository/views/repo_files.py b/rhodecode/apps/repository/views/repo_files.py index 3317f559..56229b3f 100644 --- a/rhodecode/apps/repository/views/repo_files.py +++ b/rhodecode/apps/repository/views/repo_files.py @@ -260,8 +260,7 @@ class RepoFilesView(RepoAppView): fileformat = None ext = None content_type = None - for a_type, ext_data in settings.ARCHIVE_SPECS.items(): - content_type, extension = ext_data + for a_type, content_type, extension in settings.ARCHIVE_SPECS: if fname.endswith(extension): fileformat = a_type diff --git a/rhodecode/lib/vcs/backends/base.py b/rhodecode/lib/vcs/backends/base.py index e37878d6..fa1f9f0c 100644 --- a/rhodecode/lib/vcs/backends/base.py +++ b/rhodecode/lib/vcs/backends/base.py @@ -1111,7 +1111,7 @@ class BaseCommit(object): :raise VCSError: If prefix has a problem. """ - allowed_kinds = settings.ARCHIVE_SPECS.keys() + allowed_kinds = [x[0] for x in settings.ARCHIVE_SPECS] if kind not in allowed_kinds: raise ImproperArchiveTypeError( 'Archive kind (%s) not supported use one of %s' % diff --git a/rhodecode/lib/vcs/conf/settings.py b/rhodecode/lib/vcs/conf/settings.py index c822e89e..96f4aa15 100644 --- a/rhodecode/lib/vcs/conf/settings.py +++ b/rhodecode/lib/vcs/conf/settings.py @@ -42,12 +42,16 @@ BACKENDS = { 'svn': 'rhodecode.lib.vcs.backends.svn.SubversionRepository', } -# TODO: Remove once controllers/files.py is adjusted -ARCHIVE_SPECS = { - 'tbz2': ('application/x-bzip2', '.tar.bz2'), - 'tgz': ('application/x-gzip', '.tar.gz'), - 'zip': ('application/zip', '.zip'), -} + +ARCHIVE_SPECS = [ + ('tbz2', 'application/x-bzip2', 'tbz2'), + ('tbz2', 'application/x-bzip2', '.tar.bz2'), + + ('tgz', 'application/x-gzip', '.tgz'), + ('tgz', 'application/x-gzip', '.tar.gz'), + + ('zip', 'application/zip', '.zip'), +] HOOKS_PROTOCOL = None HOOKS_DIRECT_CALLS = False