2017-07-04 20:19:02 -04:00
|
|
|
module Storage
|
2017-08-07 05:07:42 -04:00
|
|
|
class LegacyProject
|
|
|
|
attr_accessor :project
|
|
|
|
delegate :namespace, :gitlab_shell, :repository_storage_path, to: :project
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-08-15 22:49:54 -04:00
|
|
|
def ensure_storage_path_exists
|
2017-08-07 05:07:42 -04:00
|
|
|
return unless namespace
|
|
|
|
|
2017-08-04 01:30:42 -04:00
|
|
|
gitlab_shell.add_namespace(repository_storage_path, base_dir)
|
2017-07-04 20:19:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def rename_repo
|
2017-08-15 22:49:54 -04:00
|
|
|
new_full_path = project.build_full_path
|
2017-07-04 20:19:02 -04:00
|
|
|
|
2017-08-15 22:49:54 -04:00
|
|
|
if gitlab_shell.mv_repository(repository_storage_path, project.full_path_was, 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
|
2017-08-15 22:49:54 -04:00
|
|
|
gitlab_shell.mv_repository(repository_storage_path, "#{project.full_path_was}.wiki", "#{new_full_path}.wiki")
|
|
|
|
return true
|
2017-07-04 20:19:02 -04:00
|
|
|
rescue => e
|
2017-08-15 22:49:54 -04:00
|
|
|
Rails.logger.error "Exception renaming #{project.full_path_was} -> #{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
|