summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/project/export_task.rb
blob: ec287380c485a669b5a92972e3a964cffe57f118 (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
# 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

          success('Done!')
        end

        private

        def file_path_exists?
          directory = File.dirname(file_path)

          Dir.exist?(directory)
        end

        def with_export
          with_request_store do
            ::Gitlab::GitalyClient.allow_n_plus_1_calls do
              measurement_enabled? ? measurement.with_measuring { yield } : yield
            end
          end
        end
      end
    end
  end
end