debian-mirror-gitlab/app/models/storage/legacy_project.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Storage
class LegacyProject
attr_accessor :project
2018-10-15 14:42:47 +05:30
delegate :namespace, :gitlab_shell, :repository_storage, to: :project
2018-03-17 18:26:18 +05:30
def initialize(project)
@project = project
end
# Base directory
#
# @return [String] directory where repository is stored
def base_dir
namespace.full_path
end
# Disk path is used to build repository and project's wiki path on disk
#
# @return [String] combination of base_dir and the repository own name without `.git` or `.wiki.git` extensions
def disk_path
project.full_path
end
def ensure_storage_path_exists
return unless namespace
2018-10-15 14:42:47 +05:30
gitlab_shell.add_namespace(repository_storage, base_dir)
2018-03-17 18:26:18 +05:30
end
2019-03-02 22:35:43 +05:30
def rename_repo(old_full_path: nil, new_full_path: nil)
old_full_path ||= project.full_path_was
new_full_path ||= project.build_full_path
2018-03-17 18:26:18 +05:30
2019-03-02 22:35:43 +05:30
if gitlab_shell.mv_repository(repository_storage, old_full_path, new_full_path)
2018-03-17 18:26:18 +05:30
# If repository moved successfully we need to send update instructions to users.
# However we cannot allow rollback since we moved repository
# So we basically we mute exceptions in next actions
begin
2019-03-02 22:35:43 +05:30
gitlab_shell.mv_repository(repository_storage, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
2018-03-17 18:26:18 +05:30
return true
rescue => e
2019-03-02 22:35:43 +05:30
Rails.logger.error "Exception renaming #{old_full_path} -> #{new_full_path}: #{e}"
2018-03-17 18:26:18 +05:30
# Returning false does not rollback after_* transaction but gives
# us information about failing some of tasks
return false
end
end
false
end
end
end