archives: use a special name for non-hashed archives to fix caching issues.

This commit is contained in:
Milka Kuzminski 2021-03-11 10:06:40 +01:00
parent dcadd22a7d
commit bfa14dbb3a
3 changed files with 29 additions and 5 deletions

View file

@ -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):

View file

@ -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)]

View file

@ -95,7 +95,8 @@ $(document).ready(function(){
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));