diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-12 15:11:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-12 15:11:32 +0300 |
commit | 3b260cb69f464d8dea681b747dcffdeebee348ff (patch) | |
tree | bcebf3e2fcae7b4c69822b9c9fcffae5f71ce078 /app/services/projects | |
parent | 7b3a8386ceeeb87b6e7e2e5ac00365f0d063cbb8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/projects')
4 files changed, 0 insertions, 234 deletions
diff --git a/app/services/projects/hashed_storage/base_repository_service.rb b/app/services/projects/hashed_storage/base_repository_service.rb deleted file mode 100644 index 6241a3e144f..00000000000 --- a/app/services/projects/hashed_storage/base_repository_service.rb +++ /dev/null @@ -1,115 +0,0 @@ -# frozen_string_literal: true - -module Projects - module HashedStorage - # Returned when repository can't be made read-only because there is already a git transfer in progress - RepositoryInUseError = Class.new(StandardError) - - class BaseRepositoryService < BaseService - include Gitlab::ShellAdapter - - attr_reader :old_disk_path, :new_disk_path, :old_storage_version, - :logger, :move_wiki, :move_design - - def initialize(project:, old_disk_path:, logger: nil) - @project = project - @logger = logger || Gitlab::AppLogger - @old_disk_path = old_disk_path - @move_wiki = has_wiki? - @move_design = has_design? - end - - protected - - def has_wiki? - gitlab_shell.repository_exists?(project.repository_storage, "#{old_wiki_disk_path}.git") - end - - def has_design? - gitlab_shell.repository_exists?(project.repository_storage, "#{old_design_disk_path}.git") - end - - def move_repository(from_name, to_name) - from_exists = gitlab_shell.repository_exists?(project.repository_storage, "#{from_name}.git") - to_exists = gitlab_shell.repository_exists?(project.repository_storage, "#{to_name}.git") - - # If we don't find the repository on either original or target we should log that as it could be an issue if the - # project was not originally empty. - if !from_exists && !to_exists - logger.warn "Can't find a repository on either source or target paths for #{project.full_path} (ID=#{project.id}) ..." - - # We return true so we still reflect the change in the database. - # Next time the repository is (re)created it will be under the new storage layout - return true - elsif !from_exists - # Repository have been moved already. - return true - end - - gitlab_shell.mv_repository(project.repository_storage, from_name, to_name).tap do |moved| - if moved - logger.info("Repository moved from '#{from_name}' to '#{to_name}' (PROJECT_ID=#{project.id})") - else - logger.error("Repository cannot be moved from '#{from_name}' to '#{to_name}' (PROJECT_ID=#{project.id})") - end - end - end - - def move_repositories - result = move_repository(old_disk_path, new_disk_path) - project.reload_repository! - - if move_wiki - result &&= move_repository(old_wiki_disk_path, new_wiki_disk_path) - project.clear_memoization(:wiki) - end - - if move_design - result &&= move_repository(old_design_disk_path, new_design_disk_path) - project.clear_memoization(:design_repository) - end - - result - end - - def rollback_folder_move - move_repository(new_disk_path, old_disk_path) - move_repository(new_wiki_disk_path, old_wiki_disk_path) - move_repository(new_design_disk_path, old_design_disk_path) if move_design - end - - def try_to_set_repository_read_only! - project.set_repository_read_only! - rescue Project::RepositoryReadOnlyError => err - migration_error = "Target repository '#{old_disk_path}' cannot be made read-only: #{err.message}" - logger.error migration_error - - raise RepositoryInUseError, migration_error - end - - def wiki_path_suffix - @wiki_path_suffix ||= Gitlab::GlRepository::WIKI.path_suffix - end - - def old_wiki_disk_path - @old_wiki_disk_path ||= "#{old_disk_path}#{wiki_path_suffix}" - end - - def new_wiki_disk_path - @new_wiki_disk_path ||= "#{new_disk_path}#{wiki_path_suffix}" - end - - def design_path_suffix - @design_path_suffix ||= ::Gitlab::GlRepository::DESIGN.path_suffix - end - - def old_design_disk_path - @old_design_disk_path ||= "#{old_disk_path}#{design_path_suffix}" - end - - def new_design_disk_path - @new_design_disk_path ||= "#{new_disk_path}#{design_path_suffix}" - end - end - end -end diff --git a/app/services/projects/hashed_storage/rollback_attachments_service.rb b/app/services/projects/hashed_storage/rollback_attachments_service.rb deleted file mode 100644 index 4bb8cb605a3..00000000000 --- a/app/services/projects/hashed_storage/rollback_attachments_service.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Projects - module HashedStorage - class RollbackAttachmentsService < BaseAttachmentService - def execute - origin = FileUploader.absolute_base_dir(project) - - project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] - target = FileUploader.absolute_base_dir(project) - - @new_disk_path = FileUploader.base_dir(project) - - result = move_folder!(origin, target) - - if result - project.save!(validate: false) - - yield if block_given? - else - # Rollback changes - project.rollback! - end - - result - end - end - end -end diff --git a/app/services/projects/hashed_storage/rollback_repository_service.rb b/app/services/projects/hashed_storage/rollback_repository_service.rb deleted file mode 100644 index f4146ff9158..00000000000 --- a/app/services/projects/hashed_storage/rollback_repository_service.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -module Projects - module HashedStorage - class RollbackRepositoryService < BaseRepositoryService - def execute - try_to_set_repository_read_only! - - @old_storage_version = project.storage_version - project.storage_version = nil - - @new_disk_path = project.disk_path - - result = move_repositories - - if result - project.set_full_path - project.track_project_repository - else - rollback_folder_move - project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] - end - - project.transaction do - project.save!(validate: false) - project.set_repository_writable! - end - - result - rescue Gitlab::Git::CommandError => e - logger.error("Repository #{project.full_path} failed to rollback (PROJECT_ID=#{project.id}). Git operation failed: #{e.inspect}") - - rollback_migration! - - false - rescue OpenSSL::Cipher::CipherError => e - logger.error("Repository #{project.full_path} failed to rollback (PROJECT_ID=#{project.id}). There is a problem with encrypted attributes: #{e.inspect}") - - rollback_migration! - - false - end - - private - - def rollback_migration! - rollback_folder_move - project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] - project.set_repository_writable! - end - end - end -end diff --git a/app/services/projects/hashed_storage/rollback_service.rb b/app/services/projects/hashed_storage/rollback_service.rb deleted file mode 100644 index 01b343a12d1..00000000000 --- a/app/services/projects/hashed_storage/rollback_service.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -module Projects - module HashedStorage - class RollbackService < BaseService - attr_reader :logger, :old_disk_path - - def initialize(project, old_disk_path, logger: nil) - @project = project - @old_disk_path = old_disk_path - @logger = logger || Gitlab::AppLogger - end - - def execute - # Rollback attachments from Hashed Storage to Legacy - if project.hashed_storage?(:attachments) - return false unless rollback_attachments_service.execute - end - - # Rollback repository from Hashed Storage to Legacy - if project.hashed_storage?(:repository) - rollback_repository_service.execute - end - end - - private - - def rollback_attachments_service - HashedStorage::RollbackAttachmentsService.new(project: project, old_disk_path: old_disk_path, logger: logger) - end - - def rollback_repository_service - HashedStorage::RollbackRepositoryService.new(project: project, old_disk_path: old_disk_path, logger: logger) - end - end - end -end |