2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
module Project
|
|
|
|
class TreeSaver
|
|
|
|
attr_reader :full_path
|
|
|
|
|
|
|
|
def initialize(project:, current_user:, shared:, params: {})
|
|
|
|
@params = params
|
|
|
|
@project = project
|
|
|
|
@current_user = current_user
|
|
|
|
@shared = shared
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2021-09-04 01:27:46 +05:30
|
|
|
ImportExport::Json::StreamingSerializer.new(
|
2020-04-22 19:07:51 +05:30
|
|
|
exportable,
|
|
|
|
reader.project_tree,
|
|
|
|
json_writer,
|
|
|
|
exportable_path: "project"
|
|
|
|
).execute
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
true
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => e
|
2020-04-08 14:13:33 +05:30
|
|
|
@shared.error(e)
|
|
|
|
false
|
|
|
|
ensure
|
|
|
|
json_writer&.close
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def reader
|
|
|
|
@reader ||= Gitlab::ImportExport::Reader.new(shared: @shared)
|
|
|
|
end
|
|
|
|
|
|
|
|
def exportable
|
2021-01-03 14:25:43 +05:30
|
|
|
@project.present(**exportable_params)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def exportable_params
|
|
|
|
params = {
|
|
|
|
presenter_class: presenter_class,
|
|
|
|
current_user: @current_user
|
|
|
|
}
|
|
|
|
params[:override_description] = @params[:description] if @params[:description].present?
|
|
|
|
params
|
|
|
|
end
|
|
|
|
|
|
|
|
def presenter_class
|
|
|
|
Projects::ImportExport::ProjectExportPresenter
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
def json_writer
|
|
|
|
@json_writer ||= begin
|
2020-05-24 23:13:21 +05:30
|
|
|
if ::Feature.enabled?(:project_export_as_ndjson, @project.namespace, default_enabled: true)
|
2020-04-22 19:07:51 +05:30
|
|
|
full_path = File.join(@shared.export_path, 'tree')
|
2021-09-04 01:27:46 +05:30
|
|
|
Gitlab::ImportExport::Json::NdjsonWriter.new(full_path)
|
2020-04-22 19:07:51 +05:30
|
|
|
else
|
|
|
|
full_path = File.join(@shared.export_path, ImportExport.project_filename)
|
2021-09-04 01:27:46 +05:30
|
|
|
Gitlab::ImportExport::Json::LegacyWriter.new(full_path, allowed_path: 'project')
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|