gitlab-org--gitlab-foss/lib/gitlab/import_export/shared.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

module Gitlab
module ImportExport
class Shared
2017-12-02 14:49:01 -05:00
attr_reader :errors, :project
2017-12-02 14:49:01 -05:00
def initialize(project)
@project = project
@errors = []
end
2017-12-02 14:49:01 -05:00
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
2018-01-26 08:48:47 -05:00
# Debug:
2018-01-26 08:48:47 -05:00
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
2017-12-02 14:49:01 -05:00
File.join(relative_archive_path, SecureRandom.hex)
end
def relative_archive_path
2017-12-02 14:49:01 -05:00
if @project.is_a?(Project)
@project.disk_path
else
@project[:relative_path]
end
end
def error_out(message, caller)
Rails.logger.error("Import/Export error raised on #{caller}: #{message}")
end
end
end
2016-03-08 12:20:32 -05:00
end