diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/update_repository_storage_service.rb | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/app/services/projects/update_repository_storage_service.rb b/app/services/projects/update_repository_storage_service.rb index 30b99e85304..1565b534b19 100644 --- a/app/services/projects/update_repository_storage_service.rb +++ b/app/services/projects/update_repository_storage_service.rb @@ -4,6 +4,7 @@ module Projects class UpdateRepositoryStorageService < BaseService include Gitlab::ShellAdapter + Error = Class.new(StandardError) RepositoryAlreadyMoved = Class.new(StandardError) def initialize(project) @@ -17,37 +18,45 @@ module Projects # exception. raise RepositoryAlreadyMoved if project.repository_storage == new_repository_storage_key - if mirror_repositories(new_repository_storage_key) - mark_old_paths_for_archive + mirror_repositories(new_repository_storage_key) - project.update(repository_storage: new_repository_storage_key, repository_read_only: false) - project.leave_pool_repository - project.track_project_repository + mark_old_paths_for_archive - enqueue_housekeeping - else - project.update(repository_read_only: false) - end + project.update(repository_storage: new_repository_storage_key, repository_read_only: false) + project.leave_pool_repository + project.track_project_repository + + enqueue_housekeeping + + success + + rescue Error => e + project.update(repository_read_only: false) + + Gitlab::ErrorTracking.track_exception(e, project_path: project.full_path) + + error(s_("UpdateRepositoryStorage|Error moving repository storage for %{project_full_path} - %{message}") % { project_full_path: project.full_path, message: e.message }) end private def mirror_repositories(new_repository_storage_key) - result = mirror_repository(new_repository_storage_key) + mirror_repository(new_repository_storage_key) if project.wiki.repository_exists? - result &&= mirror_repository(new_repository_storage_key, type: Gitlab::GlRepository::WIKI) + mirror_repository(new_repository_storage_key, type: Gitlab::GlRepository::WIKI) end - - result end def mirror_repository(new_storage_key, type: Gitlab::GlRepository::PROJECT) - return false unless wait_for_pushes(type) + unless wait_for_pushes(type) + raise Error, s_('UpdateRepositoryStorage|Timeout waiting for %{type} repository pushes') % { type: type.name } + end repository = type.repository_for(project) full_path = repository.full_path raw_repository = repository.raw + checksum = repository.checksum # Initialize a git repository on the target path gitlab_shell.create_repository(new_storage_key, raw_repository.relative_path, full_path) @@ -56,7 +65,15 @@ module Projects raw_repository.gl_repository, full_path) - new_repository.fetch_repository_as_mirror(raw_repository) + unless new_repository.fetch_repository_as_mirror(raw_repository) + raise Error, s_('UpdateRepositoryStorage|Failed to fetch %{type} repository as mirror') % { type: type.name } + end + + new_checksum = new_repository.checksum + + if checksum != new_checksum + raise Error, s_('UpdateRepositoryStorage|Failed to verify %{type} repository checksum from %{old} to %{new}') % { type: type.name, old: checksum, new: new_checksum } + end end def mark_old_paths_for_archive |