2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
module Project
|
|
|
|
class ExportTask < BaseTask
|
|
|
|
def initialize(*)
|
|
|
|
super
|
|
|
|
|
|
|
|
@project = namespace.projects.find_by_path(@project_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def export
|
|
|
|
return error("Project with path: #{project_path} was not found. Please provide correct project path") unless project
|
|
|
|
return error("Invalid file path: #{file_path}. Please provide correct file path") unless file_path_exists?
|
|
|
|
|
|
|
|
with_export do
|
|
|
|
::Projects::ImportExport::ExportService.new(project, current_user)
|
|
|
|
.execute(Gitlab::ImportExport::AfterExportStrategies::MoveFileStrategy.new(archive_path: file_path))
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return error(project.import_export_shared.errors.join(', ')) if project.import_export_shared.errors.any?
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
success('Done!')
|
2020-05-24 23:13:21 +05:30
|
|
|
rescue Gitlab::ImportExport::Error => e
|
|
|
|
error(e.message)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def file_path_exists?
|
|
|
|
directory = File.dirname(file_path)
|
|
|
|
|
|
|
|
Dir.exist?(directory)
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_export
|
|
|
|
with_request_store do
|
2020-05-24 23:13:21 +05:30
|
|
|
# We are disabling ObjectStorage for `export`
|
|
|
|
# since when direct upload is enabled, remote storage will be used
|
|
|
|
# and Gitlab::ImportExport::AfterExportStrategies::MoveFileStrategy will fail to copy exported archive
|
|
|
|
disable_upload_object_storage do
|
|
|
|
::Gitlab::GitalyClient.allow_n_plus_1_calls do
|
|
|
|
yield
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|