debian-mirror-gitlab/lib/gitlab/import_export/shared.rb

80 lines
1.9 KiB
Ruby
Raw Normal View History

2019-02-13 22:33:31 +05:30
# frozen_string_literal: true
2016-06-22 15:30:34 +05:30
module Gitlab
module ImportExport
class Shared
2018-03-27 19:54:05 +05:30
attr_reader :errors, :project
2016-06-22 15:30:34 +05:30
2018-03-27 19:54:05 +05:30
def initialize(project)
@project = project
2016-06-22 15:30:34 +05:30
@errors = []
2019-02-13 22:33:31 +05:30
@logger = Gitlab::Import::Logger.build
2016-06-22 15:30:34 +05:30
end
2018-03-27 19:54:05 +05:30
def active_export_count
Dir[File.join(archive_path, '*')].count { |name| File.directory?(name) }
end
2016-06-22 15:30:34 +05:30
def export_path
2018-03-17 18:26:18 +05:30
@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)
2016-06-22 15:30:34 +05:30
end
def error(error)
2019-02-13 22:33:31 +05:30
log_error(message: error.message, caller: caller[0].dup)
log_debug(backtrace: error.backtrace&.join("\n"))
Gitlab::Sentry.track_acceptable_exception(error, extra: log_base_data)
2018-03-17 18:26:18 +05:30
2019-02-13 22:33:31 +05:30
add_error_message(error.message)
2016-06-22 15:30:34 +05:30
end
2019-02-13 22:33:31 +05:30
def add_error_message(message)
@errors << filtered_error_message(message)
2018-05-09 12:01:36 +05:30
end
def after_export_in_progress?
File.exist?(after_export_lock_file)
end
2016-06-22 15:30:34 +05:30
private
2018-03-17 18:26:18 +05:30
def relative_path
2018-03-27 19:54:05 +05:30
File.join(relative_archive_path, SecureRandom.hex)
2018-03-17 18:26:18 +05:30
end
def relative_archive_path
2018-03-27 19:54:05 +05:30
@project.disk_path
2018-03-17 18:26:18 +05:30
end
2019-02-13 22:33:31 +05:30
def log_error(details)
@logger.error(log_base_data.merge(details))
end
def log_debug(details)
@logger.debug(log_base_data.merge(details))
end
def log_base_data
{
importer: 'Import/Export',
import_jid: @project&.import_state&.import_jid,
project_id: @project&.id,
project_path: @project&.full_path
}
end
def filtered_error_message(message)
Projects::ImportErrorFilter.filter_message(message)
2016-06-22 15:30:34 +05:30
end
2018-05-09 12:01:36 +05:30
def after_export_lock_file
AfterExportStrategies::BaseAfterExportStrategy.lock_file_path(project)
end
2016-06-22 15:30:34 +05:30
end
end
end