Welcome to mirror list, hosted at ThFree Co, Russian Federation.

export_task.rb « project « import_export « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3cd0d3f4c2bc08314d3a2c701ddf7d1c0d306a52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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

          return error(project.import_export_shared.errors.join(', ')) if project.import_export_shared.errors.any?

          success('Done!')
        rescue Gitlab::ImportExport::Error => e
          error(e.message)
        end

        private

        def file_path_exists?
          directory = File.dirname(file_path)

          Dir.exist?(directory)
        end

        def with_export
          ::Gitlab::SafeRequestStore.ensure_request_store do
            # 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
            end
          end
        end
      end
    end
  end
end