Skip to content
Snippets Groups Projects
Verified Commit 65dbead7 authored by Nick Thomas's avatar Nick Thomas
Browse files

Fix repository archive generation when hashed storage is enabled

parent 53811074
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -270,6 +270,16 @@ class Repository
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
expire_method_caches(%i(tag_names tag_count))
@tags = nil
Loading
Loading
---
title: Fix repository archive generation when hashed storage is enabled
merge_request: 19441
author:
type: fixed
Loading
Loading
@@ -395,12 +395,12 @@ module Gitlab
nil
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
commit = Gitlab::Git::Commit.find(self, ref)
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,
Loading
Loading
@@ -412,16 +412,12 @@ module Gitlab
 
# 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
#
# FIXME: The generated prefix is incorrect for projects with hashed
# storage enabled
def archive_prefix(ref, sha, append_sha:)
def archive_prefix(ref, sha, project_path, append_sha:)
append_sha = (ref != sha) if append_sha.nil?
 
project_name = self.name.chomp('.git')
formatted_ref = ref.tr('/', '-')
 
prefix_segments = [project_name, formatted_ref]
prefix_segments = [project_path, formatted_ref]
prefix_segments << sha if append_sha
 
prefix_segments.join('-')
Loading
Loading
Loading
Loading
@@ -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_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
expect(metadata['CommitId']).to eq(SeedRepo::LastCommit::ID)
Loading
Loading
Loading
Loading
@@ -2443,6 +2443,32 @@ describe Repository do
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
set(:project) { create(:project, :repository) }
 
Loading
Loading
Loading
Loading
@@ -220,11 +220,10 @@ describe API::Repositories do
 
expect(response).to have_gitlab_http_status(200)
 
repo_name = project.repository.name.gsub("\.git", "")
type, params = workhorse_send_data
 
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
 
it 'returns the repository archive archive.zip' do
Loading
Loading
@@ -232,11 +231,10 @@ describe API::Repositories do
 
expect(response).to have_gitlab_http_status(200)
 
repo_name = project.repository.name.gsub("\.git", "")
type, params = workhorse_send_data
 
expect(type).to eq('git-archive')
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/)
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.zip/)
end
 
it 'returns the repository archive archive.tar.bz2' do
Loading
Loading
@@ -244,11 +242,10 @@ describe API::Repositories do
 
expect(response).to have_gitlab_http_status(200)
 
repo_name = project.repository.name.gsub("\.git", "")
type, params = workhorse_send_data
 
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
 
context 'when sha does not exist' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment