# HG changeset patch # User Milka Kuzminski # Date 2021-03-11 09:06:40 # Node ID ca5fbff86eef5df080e12b8f6b3dc7d376c01796 # Parent 8fc8b7ecddee8ce477d33db6db9c2a35d551c63d archives: use a special name for non-hashed archives to fix caching issues. diff --git a/rhodecode/apps/repository/tests/test_repo_files.py b/rhodecode/apps/repository/tests/test_repo_files.py --- a/rhodecode/apps/repository/tests/test_repo_files.py +++ b/rhodecode/apps/repository/tests/test_repo_files.py @@ -542,6 +542,28 @@ class TestRepositoryArchival(object): for header in headers: assert header in response.headers.items() + def test_archival_no_hash(self, backend): + backend.enable_downloads() + commit = backend.repo.get_commit(commit_idx=173) + for a_type, content_type, extension in settings.ARCHIVE_SPECS: + + short = 'plain' + extension + fname = commit.raw_id + extension + filename = '%s-%s' % (backend.repo_name, short) + response = self.app.get( + route_path('repo_archivefile', + repo_name=backend.repo_name, + fname=fname, params={'with_hash': 0})) + + assert response.status == '200 OK' + headers = [ + ('Content-Disposition', 'attachment; filename=%s' % filename), + ('Content-Type', '%s' % content_type), + ] + + for header in headers: + assert header in response.headers.items() + @pytest.mark.parametrize('arch_ext',[ 'tar', 'rar', 'x', '..ax', '.zipz', 'tar.gz.tar']) def test_archival_wrong_ext(self, backend, arch_ext): diff --git a/rhodecode/apps/repository/views/repo_files.py b/rhodecode/apps/repository/views/repo_files.py --- a/rhodecode/apps/repository/views/repo_files.py +++ b/rhodecode/apps/repository/views/repo_files.py @@ -325,17 +325,18 @@ class RepoFilesView(RepoAppView): return lf_enabled - def _get_archive_name(self, db_repo_name, commit_sha, ext, subrepos=False, path_sha=''): + def _get_archive_name(self, db_repo_name, commit_sha, ext, subrepos=False, path_sha='', with_hash=True): # original backward compat name of archive clean_name = safe_str(db_repo_name.replace('/', '_')) # e.g vcsserver.zip # e.g vcsserver-abcdefgh.zip # e.g vcsserver-abcdefgh-defghijk.zip - archive_name = '{}{}{}{}{}'.format( + archive_name = '{}{}{}{}{}{}'.format( clean_name, '-sub' if subrepos else '', commit_sha, + '-{}'.format('plain') if not with_hash else '', '-{}'.format(path_sha) if path_sha else '', ext) return archive_name @@ -385,7 +386,7 @@ class RepoFilesView(RepoAppView): # used for cache etc archive_name = self._get_archive_name( self.db_repo_name, commit_sha=short_sha, ext=ext, subrepos=subrepos, - path_sha=path_sha) + path_sha=path_sha, with_hash=with_hash) if not with_hash: short_sha = '' @@ -394,7 +395,7 @@ class RepoFilesView(RepoAppView): # what end client gets served response_archive_name = self._get_archive_name( self.db_repo_name, commit_sha=short_sha, ext=ext, subrepos=subrepos, - path_sha=path_sha) + path_sha=path_sha, with_hash=with_hash) # remove extension from our archive directory name archive_dir_name = response_archive_name[:-len(ext)] diff --git a/rhodecode/templates/summary/summary.mako b/rhodecode/templates/summary/summary.mako --- a/rhodecode/templates/summary/summary.mako +++ b/rhodecode/templates/summary/summary.mako @@ -95,7 +95,8 @@ var fname = selectedReference.raw_id + ext; var href = pyroutes.url('repo_archivefile', { 'repo_name': templateContext.repo_name, - 'fname': fname + 'fname': fname, + 'with_hash': '1' }); // set new label $(this).html(ico + ' {0}{1}'.format(escapeHtml(e.added.text), ext));