Fix hashed storage with project transfers to another namespace

With hashed storage enabled, we would fail to transfer a project to another
namespace because the provided paths were wrong. Instead, we should not
attempt to move paths at all.

Closes gitlab-org/gitlab-ee#4056
This commit is contained in:
Stan Hu 2017-11-16 22:39:29 -08:00
parent d41e66cb63
commit 0c085aaf44
3 changed files with 54 additions and 9 deletions

View file

@ -60,15 +60,8 @@ module Projects
# Notifications # Notifications
project.send_move_instructions(@old_path) project.send_move_instructions(@old_path)
# Move main repository # Directories on disk
# TODO: check storage type and NOOP when not using Legacy move_project_folders(project)
unless move_repo_folder(@old_path, @new_path)
raise TransferError.new('Cannot move project')
end
# Move wiki repo also if present
# TODO: check storage type and NOOP when not using Legacy
move_repo_folder("#{@old_path}.wiki", "#{@new_path}.wiki")
# Move missing group labels to project # Move missing group labels to project
Labels::TransferService.new(current_user, @old_group, project).execute Labels::TransferService.new(current_user, @old_group, project).execute
@ -131,5 +124,20 @@ module Projects
def execute_system_hooks def execute_system_hooks
SystemHooksService.new.execute_hooks_for(project, :transfer) SystemHooksService.new.execute_hooks_for(project, :transfer)
end end
def move_project_folders(project)
return if project.hashed_storage?(:repository)
# Move main repository
unless move_repo_folder(@old_path, @new_path)
raise TransferError.new("Cannot move project")
end
# Disk path is changed; we need to ensure we reload it
project.reload_repository!
# Move wiki repo also if present
move_repo_folder("#{@old_path}.wiki", "#{@new_path}.wiki")
end
end end
end end

View file

@ -0,0 +1,5 @@
---
title: Fix hashed storage with project transfers to another namespace
merge_request:
author:
type: fixed

View file

@ -42,6 +42,18 @@ describe Projects::TransferService do
expect(service).to receive(:execute_system_hooks) expect(service).to receive(:execute_system_hooks)
end end
end end
it 'disk path has moved' do
old_path = project.repository.disk_path
old_full_path = project.repository.full_path
transfer_project(project, user, group)
expect(project.repository.disk_path).not_to eq(old_path)
expect(project.repository.full_path).not_to eq(old_full_path)
expect(project.disk_path).not_to eq(old_path)
expect(project.disk_path).to start_with(group.path)
end
end end
context 'when transfer fails' do context 'when transfer fails' do
@ -188,6 +200,26 @@ describe Projects::TransferService do
end end
end end
context 'when hashed storage in use' do
let(:hashed_project) { create(:project, :repository, :hashed, namespace: user.namespace) }
before do
group.add_owner(user)
end
it 'does not move the directory' do
old_path = hashed_project.repository.disk_path
old_full_path = hashed_project.repository.full_path
transfer_project(hashed_project, user, group)
project.reload
expect(hashed_project.repository.disk_path).to eq(old_path)
expect(hashed_project.repository.full_path).to eq(old_full_path)
expect(hashed_project.disk_path).to eq(old_path)
end
end
describe 'refreshing project authorizations' do describe 'refreshing project authorizations' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:owner) { project.namespace.owner } let(:owner) { project.namespace.owner }