Fix repository archive generation when hashed storage is enabled
This commit is contained in:
parent
538110740a
commit
65dbead796
|
@ -270,6 +270,16 @@ class Repository
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def archive_metadata(ref, storage_path, format = "tar.gz", append_sha:)
|
||||||
|
raw_repository.archive_metadata(
|
||||||
|
ref,
|
||||||
|
storage_path,
|
||||||
|
project.path,
|
||||||
|
format,
|
||||||
|
append_sha: append_sha
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def expire_tags_cache
|
def expire_tags_cache
|
||||||
expire_method_caches(%i(tag_names tag_count))
|
expire_method_caches(%i(tag_names tag_count))
|
||||||
@tags = nil
|
@tags = nil
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix repository archive generation when hashed storage is enabled
|
||||||
|
merge_request: 19441
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -395,12 +395,12 @@ module Gitlab
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive_metadata(ref, storage_path, format = "tar.gz", append_sha:)
|
def archive_metadata(ref, storage_path, project_path, format = "tar.gz", append_sha:)
|
||||||
ref ||= root_ref
|
ref ||= root_ref
|
||||||
commit = Gitlab::Git::Commit.find(self, ref)
|
commit = Gitlab::Git::Commit.find(self, ref)
|
||||||
return {} if commit.nil?
|
return {} if commit.nil?
|
||||||
|
|
||||||
prefix = archive_prefix(ref, commit.id, append_sha: append_sha)
|
prefix = archive_prefix(ref, commit.id, project_path, append_sha: append_sha)
|
||||||
|
|
||||||
{
|
{
|
||||||
'ArchivePrefix' => prefix,
|
'ArchivePrefix' => prefix,
|
||||||
|
@ -412,16 +412,12 @@ module Gitlab
|
||||||
|
|
||||||
# This is both the filename of the archive (missing the extension) and the
|
# This is both the filename of the archive (missing the extension) and the
|
||||||
# name of the top-level member of the archive under which all files go
|
# name of the top-level member of the archive under which all files go
|
||||||
#
|
def archive_prefix(ref, sha, project_path, append_sha:)
|
||||||
# FIXME: The generated prefix is incorrect for projects with hashed
|
|
||||||
# storage enabled
|
|
||||||
def archive_prefix(ref, sha, append_sha:)
|
|
||||||
append_sha = (ref != sha) if append_sha.nil?
|
append_sha = (ref != sha) if append_sha.nil?
|
||||||
|
|
||||||
project_name = self.name.chomp('.git')
|
|
||||||
formatted_ref = ref.tr('/', '-')
|
formatted_ref = ref.tr('/', '-')
|
||||||
|
|
||||||
prefix_segments = [project_name, formatted_ref]
|
prefix_segments = [project_path, formatted_ref]
|
||||||
prefix_segments << sha if append_sha
|
prefix_segments << sha if append_sha
|
||||||
|
|
||||||
prefix_segments.join('-')
|
prefix_segments.join('-')
|
||||||
|
|
|
@ -256,7 +256,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
|
||||||
let(:expected_path) { File.join(storage_path, cache_key, expected_filename) }
|
let(:expected_path) { File.join(storage_path, cache_key, expected_filename) }
|
||||||
let(:expected_prefix) { "gitlab-git-test-#{ref}-#{SeedRepo::LastCommit::ID}" }
|
let(:expected_prefix) { "gitlab-git-test-#{ref}-#{SeedRepo::LastCommit::ID}" }
|
||||||
|
|
||||||
subject(:metadata) { repository.archive_metadata(ref, storage_path, format, append_sha: append_sha) }
|
subject(:metadata) { repository.archive_metadata(ref, storage_path, 'gitlab-git-test', format, append_sha: append_sha) }
|
||||||
|
|
||||||
it 'sets CommitId to the commit SHA' do
|
it 'sets CommitId to the commit SHA' do
|
||||||
expect(metadata['CommitId']).to eq(SeedRepo::LastCommit::ID)
|
expect(metadata['CommitId']).to eq(SeedRepo::LastCommit::ID)
|
||||||
|
|
|
@ -2443,6 +2443,32 @@ describe Repository do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#archive_metadata' do
|
||||||
|
let(:ref) { 'master' }
|
||||||
|
let(:storage_path) { '/tmp' }
|
||||||
|
|
||||||
|
let(:prefix) { [project.path, ref].join('-') }
|
||||||
|
let(:filename) { prefix + '.tar.gz' }
|
||||||
|
|
||||||
|
subject(:result) { repository.archive_metadata(ref, storage_path, append_sha: false) }
|
||||||
|
|
||||||
|
context 'with hashed storage disabled' do
|
||||||
|
let(:project) { create(:project, :repository, :legacy_storage) }
|
||||||
|
|
||||||
|
it 'uses the project path to generate the filename' do
|
||||||
|
expect(result['ArchivePrefix']).to eq(prefix)
|
||||||
|
expect(File.basename(result['ArchivePath'])).to eq(filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with hashed storage enabled' do
|
||||||
|
it 'uses the project path to generate the filename' do
|
||||||
|
expect(result['ArchivePrefix']).to eq(prefix)
|
||||||
|
expect(File.basename(result['ArchivePath'])).to eq(filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'commit cache' do
|
describe 'commit cache' do
|
||||||
set(:project) { create(:project, :repository) }
|
set(:project) { create(:project, :repository) }
|
||||||
|
|
||||||
|
|
|
@ -220,11 +220,10 @@ describe API::Repositories do
|
||||||
|
|
||||||
expect(response).to have_gitlab_http_status(200)
|
expect(response).to have_gitlab_http_status(200)
|
||||||
|
|
||||||
repo_name = project.repository.name.gsub("\.git", "")
|
|
||||||
type, params = workhorse_send_data
|
type, params = workhorse_send_data
|
||||||
|
|
||||||
expect(type).to eq('git-archive')
|
expect(type).to eq('git-archive')
|
||||||
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/)
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.gz/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the repository archive archive.zip' do
|
it 'returns the repository archive archive.zip' do
|
||||||
|
@ -232,11 +231,10 @@ describe API::Repositories do
|
||||||
|
|
||||||
expect(response).to have_gitlab_http_status(200)
|
expect(response).to have_gitlab_http_status(200)
|
||||||
|
|
||||||
repo_name = project.repository.name.gsub("\.git", "")
|
|
||||||
type, params = workhorse_send_data
|
type, params = workhorse_send_data
|
||||||
|
|
||||||
expect(type).to eq('git-archive')
|
expect(type).to eq('git-archive')
|
||||||
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/)
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.zip/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the repository archive archive.tar.bz2' do
|
it 'returns the repository archive archive.tar.bz2' do
|
||||||
|
@ -244,11 +242,10 @@ describe API::Repositories do
|
||||||
|
|
||||||
expect(response).to have_gitlab_http_status(200)
|
expect(response).to have_gitlab_http_status(200)
|
||||||
|
|
||||||
repo_name = project.repository.name.gsub("\.git", "")
|
|
||||||
type, params = workhorse_send_data
|
type, params = workhorse_send_data
|
||||||
|
|
||||||
expect(type).to eq('git-archive')
|
expect(type).to eq('git-archive')
|
||||||
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/)
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.bz2/)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sha does not exist' do
|
context 'when sha does not exist' do
|
||||||
|
|
Loading…
Reference in New Issue