2018-08-10 02:45:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-04 20:19:02 -04:00
|
|
|
module Storage
|
2017-08-07 05:07:42 -04:00
|
|
|
class LegacyProject
|
|
|
|
attr_accessor :project
|
2018-04-13 06:57:19 -04:00
|
|
|
delegate :namespace, :gitlab_shell, :repository_storage, to: :project
|
2017-08-07 05:07:42 -04:00
|
|
|
|
|
|
|
def initialize(project)
|
|
|
|
@project = project
|
|
|
|
end
|
2017-07-04 20:19:02 -04:00
|
|
|
|
2017-08-04 01:30:42 -04:00
|
|
|
# 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
|
2017-07-04 20:19:02 -04:00
|
|
|
def disk_path
|
2017-08-07 05:07:42 -04:00
|
|
|
project.full_path
|
2017-07-04 20:19:02 -04:00
|
|
|
end
|
|
|
|
|
2019-01-21 22:33:32 -05:00
|
|
|
def rename_repo(old_full_path: nil, new_full_path: nil)
|
2019-04-23 05:30:18 -04:00
|
|
|
old_full_path ||= project.full_path_before_last_save
|
2019-01-21 22:33:32 -05:00
|
|
|
new_full_path ||= project.build_full_path
|
2017-07-04 20:19:02 -04:00
|
|
|
|
2019-01-21 22:33:32 -05:00
|
|
|
if gitlab_shell.mv_repository(repository_storage, old_full_path, new_full_path)
|
2017-07-04 20:19:02 -04:00
|
|
|
# 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-01-21 22:33:32 -05:00
|
|
|
gitlab_shell.mv_repository(repository_storage, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
|
2017-08-15 22:49:54 -04:00
|
|
|
return true
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => e
|
2020-05-21 17:08:31 -04:00
|
|
|
Gitlab::AppLogger.error("Exception renaming #{old_full_path} -> #{new_full_path}: #{e}")
|
2017-07-04 20:19:02 -04:00
|
|
|
# Returning false does not rollback after_* transaction but gives
|
|
|
|
# us information about failing some of tasks
|
2017-08-15 22:49:54 -04:00
|
|
|
return false
|
2017-07-04 20:19:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-15 22:49:54 -04:00
|
|
|
false
|
2017-07-04 20:19:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|