summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/shared.rb
blob: 3d3d998a6a321bdbde87231fbf80f84e0824732b (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
module Gitlab
  module ImportExport
    class Shared
      attr_reader :errors, :project

      def initialize(project)
        @project = project
        @errors = []
      end

      def active_export_count
        Dir[File.join(archive_path, '*')].count { |name| File.directory?(name) }
      end

      def export_path
        @export_path ||= Gitlab::ImportExport.export_path(relative_path: relative_path)
      end

      def archive_path
        @archive_path ||= Gitlab::ImportExport.export_path(relative_path: relative_archive_path)
      end

      def error(error)
        error_out(error.message, caller[0].dup)
        @errors << error.message

        # Debug:
        if error.backtrace
          Rails.logger.error("Import/Export backtrace: #{error.backtrace.join("\n")}")
        else
          Rails.logger.error("No backtrace found")
        end
      end

      private

      def relative_path
        File.join(relative_archive_path, SecureRandom.hex)
      end

      def relative_archive_path
        @project.disk_path
      end

      def error_out(message, caller)
        Rails.logger.error("Import/Export error raised on #{caller}: #{message}")
      end
    end
  end
end