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
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
def initialize(project:, shared:, path_to_bundle:)
|
2019-12-21 20:55:43 +05:30
|
|
|
@repository = project.repository
|
2016-06-22 15:30:34 +05:30
|
|
|
@path_to_bundle = path_to_bundle
|
|
|
|
@shared = shared
|
|
|
|
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)
|
2016-06-22 15:30:34 +05:30
|
|
|
rescue => 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
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_accessor :repository, :path_to_bundle, :shared
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
def ensure_repository_does_not_exist!
|
|
|
|
if repository.exists?
|
|
|
|
shared.logger.info(
|
|
|
|
message: %Q{Deleting existing "#{repository.path}" to re-import it.}
|
|
|
|
)
|
|
|
|
|
|
|
|
Repositories::DestroyService.new(repository).execute
|
|
|
|
end
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|