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

repository_bundle_pipeline.rb « pipelines « projects « bulk_imports « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4307cb2bafd938c91f41100977161b857c08dd7e (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true

module BulkImports
  module Projects
    module Pipelines
      class RepositoryBundlePipeline
        include Pipeline

        abort_on_failure!
        file_extraction_pipeline!
        relation_name BulkImports::FileTransfer::ProjectConfig::REPOSITORY_BUNDLE_RELATION

        def extract(_context)
          download_service.execute
          decompression_service.execute
          extraction_service.execute

          bundle_path = File.join(tmpdir, "#{self.class.relation}.bundle")

          BulkImports::Pipeline::ExtractedData.new(data: bundle_path)
        end

        def load(_context, bundle_path)
          Gitlab::PathTraversal.check_path_traversal!(bundle_path)
          Gitlab::PathTraversal.check_allowed_absolute_path!(bundle_path, [Dir.tmpdir])

          return unless File.exist?(bundle_path)
          return if File.directory?(bundle_path)
          return if Gitlab::Utils::FileInfo.linked?(bundle_path)

          portable.repository.create_from_bundle(bundle_path)
        end

        def after_run(_)
          FileUtils.remove_entry(tmpdir) if Dir.exist?(tmpdir)
        end

        private

        def tar_filename
          "#{self.class.relation}.tar"
        end

        def targz_filename
          "#{tar_filename}.gz"
        end

        def download_service
          BulkImports::FileDownloadService.new(
            configuration: context.configuration,
            relative_url: context.entity.relation_download_url_path(self.class.relation),
            tmpdir: tmpdir,
            filename: targz_filename
          )
        end

        def decompression_service
          BulkImports::FileDecompressionService.new(tmpdir: tmpdir, filename: targz_filename)
        end

        def extraction_service
          BulkImports::ArchiveExtractionService.new(tmpdir: tmpdir, filename: tar_filename)
        end

        def tmpdir
          @tmpdir ||= Dir.mktmpdir('bulk_imports')
        end
      end
    end
  end
end