debian-mirror-gitlab/lib/gitlab/import_export/repo_restorer.rb

56 lines
1.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2016-06-22 15:30:34 +05:30
module Gitlab
module ImportExport
class RepoRestorer
include Gitlab::ImportExport::CommandLineUtil
2021-03-11 19:13:27 +05:30
attr_reader :importable
def initialize(importable:, shared:, path_to_bundle:)
2016-06-22 15:30:34 +05:30
@path_to_bundle = path_to_bundle
@shared = shared
2021-03-11 19:13:27 +05:30
@importable = importable
2016-06-22 15:30:34 +05:30
end
def restore
2019-12-21 20:55:43 +05:30
return true unless File.exist?(path_to_bundle)
2016-06-22 15:30:34 +05:30
2021-01-03 14:25:43 +05:30
ensure_repository_does_not_exist!
2019-12-21 20:55:43 +05:30
repository.create_from_bundle(path_to_bundle)
2021-03-11 19:13:27 +05:30
update_importable_repository_info
true
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2019-12-21 20:55:43 +05:30
shared.error(e)
2016-06-22 15:30:34 +05:30
false
end
2019-12-21 20:55:43 +05:30
2021-03-11 19:13:27 +05:30
def repository
@repository ||= importable.repository
end
2019-12-21 20:55:43 +05:30
private
2021-03-11 19:13:27 +05:30
attr_accessor :path_to_bundle, :shared
def update_importable_repository_info
# No-op. Overridden in EE
end
2021-01-03 14:25:43 +05:30
def ensure_repository_does_not_exist!
if repository.exists?
shared.logger.info(
2021-03-11 19:13:27 +05:30
message: %Q{Deleting existing "#{repository.disk_path}" to re-import it.}
2021-01-03 14:25:43 +05:30
)
Repositories::DestroyService.new(repository).execute
end
end
2016-06-22 15:30:34 +05:30
end
end
end
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
Gitlab::ImportExport::RepoRestorer.prepend_mod_with('Gitlab::ImportExport::RepoRestorer')